Maven Settings for multiple repositories

Rohit Sachan picture Rohit Sachan · Aug 21, 2014 · Viewed 56.6k times · Source

I have the following in settings.xml

<mirrors>
       <mirror>
          <id>paid-jars</id>
          <name>jars with license</name>
          <url>http://url:8081/nexus/content/repositories/paidjars/</url>
          <mirrorOf>!central</mirrorOf>
      </mirror>
      <mirror>
          <id>Org-central</id>
          <name>mirror of central</name>
          <url>http://url:8081/nexus/content/repositories/central/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
  </mirrors>

In pom.xml I have two jars

  1. apache-commons.jar (which I assumes to be downloaded from central)
  2. licensed.jar (which I assume to be downloaded from paid-jars)

But when I run maven clean install it tries to download licensed.jar from Org-central.

How can I make it use paid-jars to download? Is it possible first it goes to Org-central and if fails it tries at paid-jars? If so, how? I don't want to put repo entries in pom.xml


Settings.xml

<?xml version="1.0" encoding="UTF-8"?>    
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <proxies>    
    <proxy>
      <id>Proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>username</username>
      <password>******</password>
      <host>host.url</host>
      <port>8080</port>
      <nonProxyHosts>local.net|internal.com</nonProxyHosts>
    </proxy>
  </proxies>
 <mirrors>
       <mirror>
          <id>paid-jars</id>
          <name>jars with license</name>
          <url>http://url:8081/nexus/content/repositories/paidjars/</url>
          <mirrorOf>!central</mirrorOf>
      </mirror>
      <mirror>
          <id>Org-central</id>
          <name>mirror of central</name>
          <url>http://url:8081/nexus/content/repositories/central/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
  </mirrors>
  <profiles>
      <profile>
          <id>compiler</id>
          <properties>
              <JAVA_1_7_HOME>C:\Program Files (x86)\Java\jdk1.7.0_51\bin</JAVA_1_7_HOME>
          </properties>
      </profile>
  </profiles>
</settings>

Answer

Ashkrit Sharma picture Ashkrit Sharma · Aug 22, 2014

you have to setup mirror

<mirror>
  <id>nexus</id>
  <mirrorOf>*</mirrorOf>
  <url>http://internal/nexus/content/repositories/thirdparty</url>
</mirror>

 <mirror>
  <id>google</id>
  <mirrorOf>google</mirrorOf>
  <url>http://google-maven-repository.googlecode.com/svn/repository</url>
</mirror>   

then add internal & external repo

<profile>
     <id>nexus</id>
  <repositories>

    <repository>
      <id>central</id>
      <name>central</name>
      <url>http://internal/nexus/content/repositories/thirdparty</url>
    </repository>


    <repository>
      <id>google</id>
      <name>google</name>
      <url>http://google-maven-repository.googlecode.com/svn/repository</url>
    </repository>

  </repositories>
</profile>