In Maven 2, is it possible to specify a mirror for everything, but allow for failover to direct repositories?
I understand that part of the appeal of setting up a Maven mirror, such as the following:
<mirror>
<id>nexus</id>
<name>Maven Repository</name>
<mirrorOf>*</mirrorOf>
<url>http://server:8081/nexus/content/groups/public</url>
</mirror>
... is that the documentation states:
You can force Maven to use a single repository by having it mirror all repository requests.
However, is this also an indication that by having a *
mirror set up each workstation must be forced to go through the mirror?
I ask because I would like each workstation to failover and connect directly to whatever public repositories it knows about in the event that Nexus can't resolve a dependency or plugin. (In a perfect world, each developer has the access necessary to add additional proxy repositories开发者_JAVA技巧 as needed. However, sometimes that access isn't available; sometimes the Nexus server goes down; sometimes it suffers a Java heap error.)
Is this "mirror but go ahead and connect directly to public repos" failover configuration possible in Maven 2? Will it be in Maven 3?
No, there's no failover mode. You can exclude some repositories from ever going to the mirror with <mirrorOf>*,!repository</mirrorOf>
, or you can have two settings.xml
files that will behave differently and switch using --settings
if needed.
It's not possible in Maven 2. It may be possible in the future in Maven 3. We have also considered adding this possibility in Nexus to dynamically proxy artifacts. The bottom line is that most organizations want control over the proxy repos used by developers and so this feature turns out to be very popular in a repo manager.
For the same reason, having developer machines directly fall back from accessing the repo manager to the repos directly is not desirable. Then you end up losing all the benefits of proxy caching, sharing, filtering etc that you get.
One answer (implicit in my question) is that this isn't possible by design. The comment at the end of this ticket by Jason Van Zyl indicates that
The real mirror is not checked on purpose. The way repository managers work these days would break severely if we started doing this.
This configuration is possible too. It works great, there is one tough situation though , if the project is hierarchically big and not all children have the same parent, you'd have to copy over this section even to their poms. It means that everywhere else than in project that declares this fake central, that is default repo to look at, your request will go to proper maven central or to other declared repositories in the project's pom. CATCH: you use plugin X -- and maybe are not aware of it actually -- and plugin X depends on artifact Y, that in it's own pom has repo declared.... >>> no control over proxying all requests for dependencies to nexus
Another alternative is having an extra settings.xml for projects and "supply" it $mvn -s settings.xml
Third alternative is having global settings.xml as follows, and activate -P nexus only when needed, cause without fake central repository it is surprisingly working.
<settings>
<mirrors>
<mirror>
<id>nexus</id>
<name>nexus</name>
<url>http://localhost:8082/nexus-webapp-1.6.0/content/groups/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
</activeProfiles>
</settings>
Open the image in another tab/window.
精彩评论