I have 3 repositories in my settings.xml because I need artifacts from all of them. Whenever a dependency is not found, Maven tries
Downloading: http://some.server/mvn2repo/releases/org/apache/lucene/lucene-core/2.9.1/... [INFO] Unable to find resource 'org.apache.lucene:lucene-core:pom:2.9.1' in repository Downloading: http://some.server/mvn2repo/3rdParty/org/apache/lucene/lucene-core/2.9.1/... [INFO] Unable to find resource 'org.apache.lucene:lucene-core:pom:2.9.1' in repository Downloading: http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/2.9.1/lucene-core-2.9.1.pom <success>
all repositories, but most of the time finds the artifact in central (repo1) of course. I want Maven to check this repo first. I tried order of declarations in settings.xml, but did not work. According to fgysin I also tried the reverse order, which didn't change anything.
My Maven version:
C:\>mvn -v Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200) Java version: 1.6.0_15 Java home: C:\Program Files\Java\jdk1.6.0_15\jre Default locale: de_AT, platform encoding: Cp1252 OS name: "windows vista" version: "6.0" arch: "amd64" Family: "windows"
My settings.xml
<profiles> <profile> <id>space</id> <repositories> <repository> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>s1-releases</id> <name>System One Releases</name> <url>http://some.server/mvn2repo/releases</url> </repository> <repository> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>s1-3rdParty</id> <name>System One 3rd Party Releases</name> <url>http://some.server/mvn2repo/3rdParty</url> </repository> <repository> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <id>central</id> <url>http://repo1.maven.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <id>central</id> <url>http://repo1.maven.org/maven2</url> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>space</activeProfile> </activeProfiles>
Maven searches for the dependencies in the following order: Local repository then Central repository then Remote repository. If dependency is not found in these repositories, maven stops processing and throws an error.
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.
As far as I know, the order of the repositories in your pom.xml will also decide the order of the repository access.
As for configuring repositories in settings.xml, I've read that the order of repositories is interestingly enough the inverse order of how the repositories will be accessed.
Here a post where someone explains this curiosity:
http://community.jboss.org/message/576851
None of these answers were correct in my case.. the order seems dependent on the alphabetical ordering of the <id> tag, which is an arbitrary string. Hence this forced repo search order:
<repository> <id>1_maven.apache.org</id> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <url>https://repo.maven.apache.org/maven2</url> <layout>default</layout> </repository> <repository> <id>2_maven.oracle.com</id> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> <url>https://maven.oracle.com</url> <layout>default</layout> </repository>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With