Specifying Maven's local repository location as a CLI parameter

后端 未结 3 1459
长发绾君心
长发绾君心 2020-11-28 02:02

Is it possible to set the location of the local Maven repository as argument on the Maven command line?

The thing is that I don\'t use the default one in ~/.m2

相关标签:
3条回答
  • 2020-11-28 02:27

    use maven property maven.repo.local:

    mvn -Dmaven.repo.local=$HOME/.my/other/repository clean install

    No modifications to settings.xml are necessary.

    0 讨论(0)
  • 2020-11-28 02:27

    One kind of hacky way that would work is:

    1. Add <localRepository>${m2.localRepository}</localRepository> to your settings.xml
    2. In your mvn.sh or mvn.bat, add -Dm2.localRepository=<full path to home dir>/.m2/repository before the "$@" in the command that gets executed. This will make your default local repo stay where it should be.
    3. Now you can use mvn -Dm2.localRepository=... <phases/goals>. Because your command line system property gets added to the command line after the one in the mvn script, it will take precedence. (At least I'm pretty sure it works that way on both windows and linux, but testing will tell.)
    0 讨论(0)
  • 2020-11-28 02:40

    For git:

    alias mvn='mvn "-Dmaven.repo.local=$(git rev-parse --show-toplevel)/.m2/repository"'
    

    This uses a separate maven repository in each git repository

    0 讨论(0)
提交回复
热议问题