Maven Mirror - how to get around if the mirror host is unavailable?

I have a maven mirror repository (Archiva) for example.

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

However, this is a VPN, and sometimes I probably don’t use it / I can’t connect to VPM

The problem is creating out of VPN, I get this error

myMirrorHost: Unknown host myMirrorHost → [Help 1]

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

Is it possible?

+3
source share
3 answers

Try to run the assembly offline if it is not connected to the VPN

mvn -o clean package

Another option is to have a second Maven settings file to use when you are connected to another network:

mvn -s $HOME/.m2/settings-alternative.xml clean package

( ), .

+2

, , *:

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

, . 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>

, - , maven ( ).

+3

Mark anser, script , .

The main use is to write the form configuration file first ~/.m2/settings.<config>.xml, where <config>is the name of the configuration, and then set the configuration, invoking setmvn [config]without specifying that it will delete the configuration in place. This will symbolically bind to the configuration file, so if your tools change the current configuration, it will change the current configuration file.

#!/bin/bash

[ "$#" -lt 2 ] || {
    echo "Usage: $(basename $0) [profile-name]" >&2
    exit 1
}

if [ -z "$1" ] ; then
    if [ -f ~/.m2/settings.xml ] ; then
        echo "Configuration removed."
        rm -f ~/.m2/settings.xml
    else
        echo "Configuration not in place, nothing to do." >&2
    fi
else
    if [ -f ~/.m2/"settings.$1.xml" ] ; then
        [ -f ~/.m2/settings.xml ] && rm -f ~/.m2/settings.xml
        ln -s ~/.m2/"settings.$1.xml" ~/.m2/settings.xml
        echo "Configuration set to $1."
    else
        echo "Configuration not found: $1" >&2
        exit 2
    fi
fi
+1
source

All Articles