Reputation: 22948
Yesterday I asked about using an exlusive maven repository, now it turns I need to use 2, they are both private .. so concerning this link which explains about forcing maven to use one repository, how do I specify the second repository? Lets take for instance I have two of these repositories in my pom.xml now, if something is missing in the two repositories it will go and search the dependency on the public repository, how to prevent this?
<repositories>
<repository>
<id>my-internal-site</id>
<name>our maven repository</name>
<url>http://myserver/repo</url>
</repository>
<repository>
<id>my-other-internal-site</id>
<name>our 2nd maven repository</name>
<url>http://myserver/repo2</url>
</repository>
</repositories>
Would I need to alter the setting xml as this?
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>our maven repository</name>
<url>http://myserver/repo</url>
<mirrorOf>my-internal-site,my-other-internal-site</mirrorOf>
</mirror>
<mirror>
<id>my-other-internal-site</id>
<name>our 2nd maven repository</name>
<url>http://myserver/repo2</url>
<mirrorOf>my-internal-site,my-other-internal-site</mirrorOf>
</mirror>
</mirrors>
...
</settings>
Or in some other way ?
EDIT
I know that I don't need to set repositories in my pom.xml if I specify exclusive ones in settings.xml .. I'm just making a point so someone can answer my question better.. thank you
Upvotes: 4
Views: 2796
Reputation: 570285
I'd still use:
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
And add the other internal repository as a "Proxy Repository" (most repository managers can proxy repositories) in the first one.
But I wonder why you have to do this. Can't all projects use the same internal repository?
Upvotes: 2
Reputation: 5867
You don't need to duplicate the repository in mirrors - the configuration you illustrated would have no effect with only one of the mirrors being selected for given mirrorOf
.
Mirrors replace repositories already defined, either for a given ID or a collection of IDs (external:*
, etc.). If you need to add a repository, you must add a repository element either in the POM or in the settings.
You probably want something like this:
<settings>
...
<profiles>
<profile>
<id>second-repo</id>
<repositories>
<repository>
<id>second-repo</id>
<url>http://myrepo/second-repo</url>
<!-- add releases / snapshots config as appropriate here -->
</repository>
</repositories>
<!-- duplicate for pluginRepositories here if needed -->
</profile>
</profiles>
<activeProfiles>
<activeProfile>second-repo</activeProfile>
</activeProfiles>
...
<mirrors>
<mirror>
<id>corporate-repo</id>
<url>http://myrepo/my-group</url>
<mirrorOf>external:*,!second-repo</mirrorOf>
</mirror>
</mirrors>
...
</settings>
Upvotes: 4