6

I am participating in two projects, both of which are using private maven repository (using nexus). Since both of them are using their own 3rd party libraries, I want to set corresponding mirror for each project. Fortunately, I can freely edit project1's pom.xml.

Is there any way that I can inject some variables or settings so that my ~/.m2/settings.xml use mirror1 for project1, and mirror2 as default (for project2)?

Well.. I looked up many stackoverflow questions and answers, but I am a newbie in maven and I could not understand and adopt those answers in my project..

UGO
  • 353
  • 3
  • 13
  • Are you using Jenkins? - http://stackoverflow.com/questions/14023836/now-getting-401-unauthorized-in-jenkins-when-deploying-artifact-to-archiva-maven/14024843#14024843 – Mark O'Connor Jan 27 '13 at 11:16
  • I'm using jenkins only for CI server and coding on eclipse.. but thanks for the link! – UGO Feb 05 '13 at 03:00

2 Answers2

4

Unfortunately there is no way to support multiple mirror definitions within a single settings file.

You will need to create two maven settings files and then parameterize the maven build, e.g. mvn <cmd> -s <path/to/settings.xml>.

MrsTang
  • 3,119
  • 1
  • 19
  • 24
2

After maven 3.3.1, use the project-settings-extension to load the project settings, and put project specific mirrors into ${basedir}/.mvn/settings.xml in each project.

in ${basedir}/.mvn/extensions.xml

    <extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
      <extension>
        <groupId>com.github.gzm55.maven</groupId>
        <artifactId>project-settings-extension</artifactId>
        <version>0.2.4</version>
      </extension>
    </extensions>

in ${basedir}/.mvn/settings.xml

<settings>
  <mirrors>
    <mirror>
      <id>id</id>
      <url>https://url-for-this-project/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
</settings>
James Z.M. Gao
  • 516
  • 1
  • 8
  • 13