The solution is not using mirror-any, but using specific repository declarations with dependencies pom cleanups. This way you'll be as protected from going to unauthorized repos as with mirror-any and you'll be able to declare profiles (work and home) with different servers in each of them.
maven - mirror depending on project
質問
I have a mirror for maven central setup like this in settings.xml:
<mirrors>
<mirror>
<id>artifactory-other</id>
<mirrorOf>*</mirrorOf>
<url>http://some.internal.site/artifactory/repo</url>
<name>Artifactory</name>
</mirror>
</mirrors>
But this server is accessible only from the internal network. When I'm at home and tinker with some side projects I need to access the real repositories. For now I just comment this mirror out, but it's cumbersome.
How can I make it automatic? Is it possible to define a profile with separate mirrors and automatically activated based on project path? Is there some simple solution?
解決 2
他のヒント
Unfortunately there is not an out-of-the-box solution with Maven. Usual i check in my settings.xml
via git and having different branches for different networks like at work, home etc. The result is reduced to a simple
git checkout HOME
or
git checkout WORK
etc.
With new 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.0.1</version>
</extension>
</extensions>
in ${basedir}/.mvn/settings.xml
<settings>
<mirrors>
<mirror>
<id>id</id>
<url>https://internal-repo/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
Then the project will be built out-of-box in the internal network with mvn test
, and not pollute your personal .m2/settings.xml