Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven repository mirrors

Tags:

maven-2

Normally, I have the following mirror configured in my Maven settings.xml

<mirror>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
  <mirrorOf>*</mirrorOf>
</mirror>

My understanding is that this mirror prevents Maven from downloading dependencies from the internet, i.e. it will only look for them in this internal repository.

However, whenever I want to add a dependency that isn't in this internal repository, I have to comment out the text above and add the following to the project's pom.xml

<repository>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
</repository>

When I make these changes Maven will check for dependencies in the local repo, and if not found, download them from the internet to the local repo. Once I have the dependencies I need, I then change my configuration back.

Is there a way to get the behaviour I want - always check the internal repo, then the public (Internet) repos - without having to add the <repository> to every project's pom.xml?

Ideally I would like to specify this repository once in settings.xml, but it seems that you can only configure mirrors there.

like image 731
Dónal Avatar asked Feb 11 '11 17:02

Dónal


People also ask

What is mirror repository in Maven?

You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories.

How do I mirror my Nexus repository?

Once you have created a proxy repository, you should configure Nexus to download artifacts from one or more mirrors. To configure mirrors, click on Repositories under the View/Repositories section of the Nexus menu, select the proxy repository you want to configure, and then select the Mirrors tab for this repository.

How do you fix a blocked mirror for repository?

Solution. This issue can be resolved by adding mirror repositories (using mirrorOf) to the ~/. m2/settings. xml file to redirect the mirrors referenced in the Maven error to HTTPS.

What are the different types of Maven repositories?

There are 3 types of maven repository: Local Repository. Central Repository. Remote Repository.


1 Answers

You could try to configure maven to use the mirror only for the central repository or to exclude the repository identified by some id.

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>central</mirrorOf>
</mirror>

Or

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>*,!internal-repository</mirrorOf>
</mirror>

The examples were adapted from maven settings and guide to mirror settings.

like image 66
Jörn Horstmann Avatar answered Oct 03 '22 15:10

Jörn Horstmann