maven: Is it possible to override location of local repository via the use of command line option or env variable?

MavenMaven 2

Maven Problem Overview


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?

Maven Solutions


Solution 1 - Maven

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.

Solution 2 - Maven

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnthony KongView Question on Stackoverflow
Solution 1 - MavenRaghuramView Answer on Stackoverflow
Solution 2 - MavenMichaelView Answer on Stackoverflow