Search code examples
mavenubuntuintellij-15

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


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?


Solution

  • 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.