How to move maven directory ".m2" from my home directory after installing IntelliJ
Asked Answered
S

2

5

I've just installed IntelliJ 15 on Ubuntu and wanted to update maven repository indices, I am having disk space errors because my home folder is on a limited size partition.

I am totally lost trying to move ~/.m2 to somewhere else. I've tried IntelliJ settings and changed paths and maven settings but didn't work and most of the time they return to the home folder after restarting IntelliJ.

I wanted to add that I didn't install maven (using apt-get install maven). Would this help or give more control?

Sardou answered 27/2, 2016 at 13:31 Comment(1)
You can create a folder wherever your want and make a symlink at ~/.m2.Turbulence
C
9

You can modify the location of the Maven local repository by modifying the Maven settings. From Configuring your Local Repository:

The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/.

<settings>
  ...
  <localRepository>/path/to/local/repo/</localRepository>
  ...
</settings>

Note: The local repository must be an absolute path.

Since you are using the Maven installation that is shipped with IntelliJ and not your own Maven version, you can create a Maven user settings:

  1. Create a file settings.xml under ${user.home}/.m2/
  2. Have the following content in it:

    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
      <localRepository>/path/to/local/repo</localRepository>
    </settings>
    

Maven will read this file and use the specified local repository.

Chui answered 27/2, 2016 at 13:43 Comment(3)
Do you think it is more neat to install maven as a separate installation? Also can I install maven once on a server and all PCs on the network use that same folder? instead of having the GBs over and over.Sardou
@Sardou Having a separate Maven installation has some advantage: you can then use Maven directly on the command line outside of an IDE. Although I've never tested it, you probably can put that Maven repo on a shared network folder yeah.Chui
The localRepository tag works well even with drive letters, e.g. D:/data/.m2/repositoryCaduceus
I
0

Another alternative I found is also by eclipse itself.

Create the setting.xml file in my D:\TAAS\settings.xml directory as follows:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>D:\TAAS\.m2\repository</localRepository>
</settings>

Then I configured it by the eclipse itself according to the following figure.

enter image description here

This is an option for maven embedded versions.

enter image description here

Istle answered 25/4, 2017 at 21:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.