maven command line how to point to a specific settings.xml for a single command?
Asked Answered
L

4

241

Is it possible to point to a specific settings file in order to override the default settings.xml being used by maven for a single command? Example:

mvn clean install -Dparam # -> pass specific settings file path as param to override default "home/.m2/settings.xml"
Laddie answered 13/8, 2014 at 4:7 Comment(0)
R
446

You can simply use:

mvn --settings YourOwnSettings.xml clean install

or

mvn -s YourOwnSettings.xml clean install
Retrospection answered 13/8, 2014 at 6:22 Comment(15)
Do you mean the local cache ? Can be defined inside settings.xml or via command line -Dmaven.repo.local=$HOME/.my/other/repositoryRetrospection
@NeerajSinghChouhan I know it's a little late, but in Eclipse, open Window > Preferences > Maven > User Settings. Specify a different User Settings (settings.xml) file there, then click Update Settings.Orelee
Is this a one off use, or does it set that location permanently?Sible
--settings did not work for me, but -s did. Maven version Apache Maven 3.6.1.Recruitment
I ran mvn install with a non default settings.xml option via -s and the artifacts were posted to the default .m2 repository and not the repo specified in -s. I then tried specifying a non existent settings file via -s and it complained that the file didn't exist. So maven appears to be recognizing that I am specifying a non default file, but choosing not to use it or not use it fully.Oecd
You can define a global settings file via -gs,--global-settings and a user settings file via -s...In user settings file you can override things If I correctly understand your question.Retrospection
--settings not worked because it is defined wrong, it should have equals sign, e.g. --settings=.mvn/settings.xmlGamali
Same thing happened with me as well. The option suggested by @Retrospection worked for me. If someone in the future comes across this problem. This is the correct option mvn -gs=/usr/local/Cellar/maven/3.6.3_1/libexec/conf/settings_.xml clean installRies
use --global-settings=.mvn/settings.xml if you just need to override the local maven repository while still loading servers/mirrors/profiles etc from ~/.m2/settings.xmlWaneta
@Retrospection settings=.mvn/settings.xml only works if .mvn is in user.dir. This use case demonstrates the need for a property that exposes the highest basedir without relying on plugins or even extensions. After discovering what it is (I see Maven will recursive up the directory tree to find .mvn), Maven simply needs to make it available, so that it can be used in --settings=${maven.basedir}/.mvn/settings.xml etc. Do you see any issues with this?Waneta
The settings.xml is global not project based. So the location for settings.xml is your home directory in $HOME/.m2/ nowhere else. Apart from that it could contain credentials which should never be put in your project. The .mvn directory is intended for extensions not for settings.xml file...Retrospection
@Retrospection Do you know if the Maven settings file can be configured via an environment variable (instead of the -s option)? Such as MAVEN_SETTINGS_FILE=/some/path/settings.xml?Jodijodie
No it can not be configuration via environment variable.Retrospection
@Jodijodie Please comment in english.Retrospection
what if two servers are in the servers list in settings.xml. The project attempts to pull the library from the nexus server instead of the packages and registries.Jinnah
S
12

I just find it very difficult, It was still not working for me. Then I checked the comments and understood that you have to override global settings. Pointed by @khmarbaise I am adding this in a new answer.

mvn -gs /local-path/settings.xml clean install

mvn --global-settings /local-path/settings.xml clean install
Suint answered 23/4, 2021 at 19:38 Comment(1)
-s didnot work for me. -gs worked for me. TMcginn
E
6

You may need to override both global and user settings. This worked for me:

mvn -s C:\settings.xml -gs C:\settings.xml clean install
Esophagus answered 5/8, 2022 at 10:19 Comment(0)
S
0

If you are using Intellij IDEA, and using ".mvn/maven.config" file inside your project to override default settings.xml file used by maven, you must use FULL syntax inside "maven.config" file.

VALID "maven.config" file:

--settings=C:\path\to\conf\my_settings.xml
--global-settings=C:\path\to\conf\my_settings.xml

Running "mvn clean" command from IntelliJ terminal with INVALID "maven.config":

-s C:\path\to\conf\my_settings.xml
-gs C:\path\to\conf\my_settings.xml

[ERROR] Error executing Maven.
[ERROR] Illegal char <:> at index ...

This answer was derived from comments under khmarbaise answer, and was added as seperate answer for visibility.

Shan answered 23/7, 2023 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.