Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Mirror - how to bypass if mirror host is not available?

Tags:

maven

vpn

I have a maven mirror repository (Archiva) e.g.

<settings>
   <mirrors>     
        <mirror>
        <id>archiva</id>
        <mirrorOf>*</mirrorOf>
        <url>http://myMirrorHost:8080/archiva/repository/internal</url>     
    </mirror>
       </mirrors>
       ...

However this is behind a VPN, and sometimes I rather not use it / can't connect to the VPM

The issue is when building outside the VPN, I get this error

myMirrorHost: Unknown host myMirrorHost -> [Help 1]

When I would like it instead to timeout / not use the mirror if not found

Is that possible?

like image 925
Eran Medan Avatar asked May 16 '12 22:05

Eran Medan


People also ask

Where should mirror be placed in POM XML?

To configure a mirror of a given repository, you provide it in your settings file ( ${user. home}/. m2/settings. xml ), giving the new repository its own id and url , and specify the mirrorOf setting that is the ID of the repository you are using a mirror of.

What is the difference between mirror and repository in Maven?

Mirror means a repository that is used as a passerelle/proxy to an other repository. When using a repository manager like Nexus, Artiafactory, Archiva... you dispose of one local entreprise repository wich proxifies remotes ones. So there is no need to declare too many repositories in your pom or setting.

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.

What is default Maven settings XML?

Maven's default settings. xml is a template with comments and examples so you can quickly tweak it to match your needs. Here is an overview of the top elements under settings : <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


1 Answers

I had a similar situation and I changed the mirror settings to mirror central, not *:

<mirrors>     
 <mirror>
  <id>archiva</id>
  <mirrorOf>central</mirrorOf>
  <url>http://myMirrorHost:8080/archiva/repository/internal</url>     
 </mirror>
</mirrors>

Then in a profile, I define another repository, e.g. ibiblio:

<profile>
  <id>myprofile</id>

 <activation>
  <activeByDefault>true</activeByDefault>
 </activation>

  <repositories>
    <repository>
      <id>ibiblio.org</id>
       <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
       <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url> 
    </repository>
  </repositories>  
</profile>

Now when something is not found in the mirror, or the mirror host is not reachable, maven tries the other repository (which is a mirror of central).

like image 186
Assen Kolov Avatar answered Sep 28 '22 00:09

Assen Kolov