3

I have a settings.xml which looks like below:-

<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">
   <servers>
      <server>
         <id>nReleases</id>
         <username>test</username>
         <password>test123</password>
      </server>
      <server>
         <id>nSnapshots</id>
         <username>test</username>
         <password>test123</password>
      </server>
   </servers>

<profiles>
    <profile>
        <id>space</id>
        <repositories>
           <repository>
                <id>central</id>
                <url>http://repo1.maven.org/maven2</url>
            </repository>
            <repository>
                <id>nReleases</id>
                <name>Releases</name>
                <url>http://someserver/repository/maven-releases/</url>
            </repository>
           <repository>
                <id>nSnapshots</id>
                <name>Snapshots</name>
                <url>http://someserver/repository/maven-snapshots/</url>
            </repository>
        </repositories>
    </profile>
</profiles>

<activeProfiles>
    <activeProfile>space</activeProfile>
</activeProfiles>
</settings>

I want maven to check repo1.maven.org first and then only look in someserver. Can someone let me know how this can be achieved?

I am using Maven 3.3.9.

I have gone through this question and tried to change the order in which repos are declared in profile but it did not help.

<profile>
    <id>space</id>
    <repositories>   
        <repository>
            <id>nReleases</id>
            <name>Releases</name>
            <url>http://someserver/repository/maven-releases/</url>
        </repository>
        <repository>
            <id>nSnapshots</id>
            <name>Snapshots</name>
            <url>http://someserver/repository/maven-snapshots/</url>
        </repository>
        <repository>
            <id>central</id>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
    </repositories>
</profile>

Logs while doing mvn clean install

tuk-MacBook-Pro-4:camel tuk$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building camel 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://someserver/repository/maven-releases/org/apache/camel/camel-redis/2.16.3/camel-redis-2.16.3.pom
Downloading: http://someserver/repository/maven-snapshots/org/apache/camel/camel-redis/2.16.3/camel-redis-2.16.3.pom
Community
  • 1
  • 1
tuk
  • 5,941
  • 14
  • 79
  • 162
  • Since Maven 3, it resolves repository in their declaration order in the settings, see also https://issues.apache.org/jira/browse/MNG-4400. I also made a simple test to verify that. Can you post the logs you have with the first set-up? For the snapshot repository, you need to enable snapshots, otherwise, Maven won't download those. – Tunaki Oct 23 '16 at 11:50
  • Updated the question. – tuk Oct 23 '16 at 12:19
  • 1
    Hm it could be that Maven already tried `repo1.maven.org` and doesn't try again unless you force it. Try with `mvn -U clean install`. Also try to remove the `.lastUpdated` files in your local repositories. – Tunaki Oct 23 '16 at 13:25
  • Yeah you are right. Actually there is no artifactId named camel-redis. It is actually named `spring-camel-redis`. It already tried repo1.maven.org. As you suggested doing `mvn -U clean install` it again tried `repo1.maven.org` & then `someserver`. Can you post your comment as answer so that I can accept it? – tuk Oct 23 '16 at 14:51

1 Answers1

5

The order of the repository inside the settings was not clearly specified in Maven 2, but starting with Maven 3 (and the fix of of MNG-4400), the repositories are always tried in their declaration order in the settings.

What can happen, and what is likely the cause of your problem, is that Maven tries a repository, fails in doing so, and stores in your local repository the fact that it tried and failed. This results in the creation of .lastUpdated files in your local repository, storing this information. The consequence is that Maven will not re-try to download the dependency from a repository where it knows the download failed in the past. Thus, when you start a command and the project requires an artifact not present in your local repository, Maven will still try the repositories in their order of declaration, but it will skip the ones it knows already failed.

But you can force it to bypass this mechanism by passing the -U flag on the command line. It forces Maven to update the releases and snapshots dependencies, without looking into .lastUpdated files. This way, it will re-try every active remote repositories.

Community
  • 1
  • 1
Tunaki
  • 132,869
  • 46
  • 340
  • 423