.M2 , Settings.Xml in Ubuntu

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

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.

Why can't I find my settings.xml under ~/.m2?


There are two locations where a settings.xml file may live:

The Maven install: ${maven.home}/conf/settings.xml

The user’s install: ${user.home}/.m2/settings.xml

The former settings.xml are also called global settings, the latter
settings.xml are referred to as user settings. If both files exists,
their contents gets merged, with the user-specific settings.xml being
dominant.

Tip: If you need to create user-specific settings from scratch, it’s
easiest to copy the global settings from your Maven installation to
your ${user.home}/.m2 directory. Maven’s default settings.xml is a
template with comments and examples so you can quickly tweak it to
match your needs.

Maven Settings Reference Guide

So simply

  1. navigate to your maven directory under ${maven.home}/conf/settings.xml
  2. and copy&paste your settings.xml to ${user.home}/.m2/

How do I find out which settings.xml file maven is using

Use the Maven debug option, ie mvn -X :

Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/java/apache-maven-3.0.3
Java version: 1.6.0_12, vendor: Sun Microsystems Inc.
Java home: /usr/java/jdk1.6.0_12/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-32-generic", arch: "i386", family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/java/apache-maven-3.0.3/conf/settings.xml
[DEBUG] Reading user settings from /home/myhome/.m2/settings.xml
...

In this output, you can see that the settings.xml is loaded from /home/myhome/.m2/settings.xml.

Why maven settings.xml file is not there?

settings.xml is not required (and thus not autocreated in ~/.m2 folder) unless you want to change the default settings.

Standalone maven and the maven in eclipse will use the same local repository (~/.m2 folder). This means if some artifacts/dependencies are downloaded by standalone maven, it will not be again downloaded by maven in eclipse.

Based on the version of Eclipse that you use, you may have different maven version in eclipse compared to the standalone. It should not matter in most cases.

Which folder does the Maven settings.xml file belong in?

Both answers are correct.

Basic config file for maven is inside mvn/conf/settings and you could add some configuration (or override basic config) with your personal maven settings file located in ~.m2/settings.xml

How to specify an alternate location for the .m2 folder or settings.xml permanently?

You need to add this line into your settings.xml (or uncomment if it's already there).

<localRepository>C:\Users\me\.m2\repo</localRepository>

Also it's possible to run your commands with mvn clean install -gs C:\Users\me\.m2\settings.xml - this parameter will force maven to use different settings.xml then the default one (which is in $HOME/.m2/settings.xml)



Related Topics



Leave a reply



Submit