Issue
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..
Solution
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>
Answered By - James Z.M. Gao
Answer Checked By - Terry (JavaFixing Volunteer)