Currently we specify the location of local repository in the settings.xml. Is it possible to override this setting via command line or env variable, such that I can use an alternative location sometimes?
2 Answers
You would need to specify the maven.repo.local
parameter to do this.
mvn package -Dmaven.repo.local=/alternate/repo/location
Here is a related SO question.
-
4The local repository must be an absolute path, maven.apache.org/guides/mini/guide-configuring-maven.html.– luka5zDec 28, 2016 at 16:20
-
1@luka5z: Thanks for the important doc ref, but I can say with experience the path can be relative for
--define maven.repo.local=local/repo/here
. Maybe absolute paths are only required forsettings.xml
? Dec 23, 2018 at 14:29 -
Use the localRepository setting in your settings.xml file. Example:
<settings>
<localRepository>/repo</localRepository>
...
</settings>
See here for more info.
You can also set the repository via the command line using "-Dmaven.repo.local=" such as:
mvn -U clean install -Dmaven.repo.local=C:\tmp
-
1We have already done it in our settings.xml. I want to override it when I invoke maven in a shell Feb 3, 2012 at 5:13
-
1If maven is using that settings.xml, even when you invoke it from a shell, it should pick up that setting. It's very common for windows users to need to set that due to spaces in their home directory "c:\documents and settings\blah"– MichaelFeb 3, 2012 at 15:52
-
1Just ran a test using " <localRepository>/Users/michael/Desktop/repository</localRepository> " in my settings.xml file. And now when I build anything from command line (or ide) it's putting the artifacts there.– MichaelFeb 3, 2012 at 15:58
-
1Sorry, misread your question. The answer above is correct. You can use the "-Dmaven.repo.local=/alternate/repo/location" option on the commands.– MichaelFeb 3, 2012 at 17:41
1.0-SNAPSHOT
as your version. Having separate .m2 repos circumvents a lot of this.