Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple repositories in Maven

Tags:

maven

I have a project that uses an internal repository and the central repository. Is there a way I can configure the settings.xml such that I can use both instead of just one? When I added

<mirrors>
    <mirror>
        <id>MY ID</id>
        <url>MY URL</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

in settings.xml, I can look into my own internal repository but it overrides the central repository.

I am sure this is a commonly encountered problem for people new to Maven.

like image 469
Some Newbie Avatar asked Oct 11 '12 16:10

Some Newbie


People also ask

How does Maven decide which repository to use?

By resolving the most recent version available from the list of repositories.

How many repositories are there in Maven?

There are exactly two types of repositories: local and remote: the local repository is a directory on the computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you have not yet released.


1 Answers

There are a few of ways to do this.

The best, IMO, is to have your local repository server act as a proxy for Maven Central. Both Nexus and Artifactory do this out of the box. If you're using Apache or another web server, you should switch.

You can also update your settings exclude the target server from your mirror:

<mirrorOf>*,!MyOtherRepository</mirrorOf>

This works if you have multiple local repository servers, but I don't think you can exclude central this way: by default, Maven looks for artifacts in central, and your server acts as a stand-in for it.

Which leaves explicit repository entries in your POMS, which reference the local repository. If your local repository just serves your artifacts, this might be the second-simplest thing to do (especially if you use a parent POM that holds the repository specification).

like image 139
parsifal Avatar answered Oct 16 '22 20:10

parsifal