78
votes

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
It didn't occur to me why this would be useful until now - if you're working on several branches (a release branch, a trunk branch) and the source tree is complex, trying to get compilation to work can be a nightmare if you're just using 1.0-SNAPSHOT as your version. Having separate .m2 repos circumvents a lot of this.Sridhar Sarnobat

2 Answers

138
votes

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.

18
votes

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