Friday, 27 May 2016

Maven Settings Everywhere

Maven can have its settings.xml defined in more ways:

1. Global settings: inside %MAVEN_INSTALL_FOLDER%/conf/
   This file is always used! And you should be aware about this in cases you will also take settings.xml in other way.

2. User settings:  inside %USER_HOME%/.m2/
   This file is optional. Any settings defined in the user settings take precedence over the corresponding global settings.

3. Command line: through --settings %SETTINGS_FILE_PATH%
If there is a global settings file, but in some cases you must use another settings file from command line, you should also override the global settings  from command line with:

  --global-settings %SETTINGS_FILE_PATH%

One problem I encountered if you do not do it so is related to mirrors. For example you can have in global settings file:


and inside settings.xml used through command line other mirror like:


and a repository with id = mydependency  which must be resolved from a specific url repo (other than http://myrepo2/).

Because of the mirror in global settings mydependency wont't be resolved by its specific repo, but from the url http://myrepo/ (because of mirror rules) and it will not be found!