371

How do I use maven command line to determine which settings.xml file Maven is picking up?

7 Answers 7

431

Start maven with -X option (debug) and examine the beginning of the output. There should be something like this:

...
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from c:\....\apache-maven-3.0.3\conf\settings.xml
[DEBUG] Reading user settings from c:\....\.m2\settings.xml
[DEBUG] Using local repository at C:\....\repository
...

(Original directory names are removed by me)

4
  • 12
    Perhaps this wasn't in the debug output until maven 3 was released, but your post some 2.5 years later is finally the exact answer I was looking for (sorry for the 6 month delay in noticing it).
    – harschware
    Nov 12, 2012 at 17:25
  • The version of maven I was using, maven2.x, did not show this important detail when the -B flag was used. ... Unfortunate, if you're trying to debug what is going on with a Jenkins server. Aug 12, 2019 at 19:13
  • 1
    I got a lot of output from mvn -X, which quickly scrolled beyond the buffer (on Windows) .Resolved by using mvn -X |more instead followed by CTRL+C to end the output. Jul 11, 2020 at 9:16
  • And if you don't want to scroll through all the output you can grep for the settings like: mvn help:effective-settings -X | grep "settings from".Or using PowerShell: mvn help:effective-settings -X | Select-String "settings from".
    – dStulle
    Aug 25 at 8:17
197

You can use the maven help plugin to tell you the contents of your user and global settings files.

mvn help:effective-settings

will ask maven to spit out the combined global and user settings.

1
191

Your comment to cletus' (correct) answer implies that there are multiple Maven settings files involved.

Maven always uses either one or two settings files. The global settings defined in (${M2_HOME}/conf/settings.xml) is always required. The user settings file (defined in ${user.home}/.m2/settings.xml) is optional. Any settings defined in the user settings take precedence over the corresponding global settings.

You can override the location of the global and user settings from the command line, the following example will set the global settings to c:\global\settings.xml and the user settings to c:\user\settings.xml:

mvn install --settings c:\user\settings.xml 
     --global-settings c:\global\settings.xml

Currently there is no property or means to establish what user and global settings files were used from with Maven. To access these values, you would have to modify MavenCli and/or DefaultMavenSettingsBuilder to inject the file locations into the resolved Settings object.

4
  • 1
    its would be great if we could provide multiple user's settings.xml, so we could use them with different projects for example. I know that we could use a profile. But it would be lot better if there would be a separate file. It's not possible, right?! Cheers!
    – despot
    Jan 29, 2012 at 15:59
  • I was looking for a solution to override my user settings just once without having to tamper with the file. So I just used the global file for the user settings. I.e. --settings c:\global\settings.xml this way the user file got omitted
    – msp
    May 14, 2013 at 14:49
  • @despot, late to the party but in a way you can through multiple profiles defined and some custom 'triggers': maven.apache.org/settings.html#Activation Sep 9, 2016 at 9:53
  • It always ask for pom in current folder. "The goal you specified requires a project to execute but there is no POM in this directory (/). Please verify you invoked Maven from the correct directory. -> [Help 1]"
    – Nilesh
    Jul 4, 2018 at 2:37
44

This is the configuration file for Maven. It can be specified at two levels:

  1. User Level. This settings.xml file provides configuration for a single user, and is normally provided in ${user.home}/.m2/settings.xml.

              NOTE: This location can be overridden with the CLI option:
    
              -s /path/to/user/settings.xml
    
  2. Global Level. This settings.xml file provides configuration for all Maven users on a machine (assuming they're all using the same Maven installation). It's normally provided in ${maven.home}/conf/settings.xml.

              NOTE: This location can be overridden with the CLI option:
    
              -gs /path/to/global/settings.xml
    
2
  • 1
    the property is M2_HOME, not maven.home Aug 11, 2009 at 21:31
  • It doesn't matter. If you set the environment variable using maven.home, it will not a problem
    – firstthumb
    Aug 11, 2009 at 21:54
31

The M2_HOME environment variable for the global one. See Settings Reference:

The settings element in the settings.xml file contains elements used to define values which configure Maven execution in various ways, like the pom.xml, but should not be bundled to any specific project, or distributed to an audience. These include values such as the local repository location, alternate remote repository servers, and authentication information. There are two locations where a settings.xml file may live:

  • The Maven install: $M2_HOME/conf/settings.xml
  • A user's install: ${user.home}/.m2/settings.xml
3
  • If this answer is to imply that determining repository is done only by examining the environment then this is a valid answer. I was hoping to learn of a command line switch or something that gives a definitive list of qualified paths for all settings.xml files used... I think there is probably no such mechanism.
    – harschware
    Aug 11, 2009 at 16:51
  • 4
    +1 answer, Cletus. I think it's worthwhile to mention the next line from your "Settings Reference" link: 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. Apr 17, 2014 at 14:23
  • 1
    The need to have a machine specific configuration to find the private repositories pains me so much. I realize this is the status quo in Java ecosystem but it leads to terribly unreproducible build setups.
    – jpierson
    Jul 27, 2018 at 19:46
28

Quick and dirty method to determine if Maven is using desired settings.xml would be invalidate its xml and run some safe maven command that requires settings.xml.

If it reads this settings.xml then Maven reports an error: "Error reading settings.xml..."

1
  • 3
    While Cletus' answer was very informative, this answer is in the strictest sense more what I was looking for (given there seems to be a lack of any settings.xml file reporting mechanism in Maven itself)
    – harschware
    Sep 18, 2009 at 15:56
13

If you are debugging and wasting time like me, this will give exact details including passwords. :P

mvn help:effective-settings -DshowPasswords=true

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.