如何在Maven settings.xml中设置存储库的顺序

时间:2011-03-16 12:42:26

标签: java maven dependency-management

我在settings.xml中有3个存储库,因为我需要来自所有存储库的工件。每当找不到依赖项时,Maven就会尝试

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>

所有存储库,但大多数情况下当然会在中心(repo1)中找到工件。我希望Maven先检查这个回购。我在settings.xml中尝试了声明顺序,但是没有用。根据 fgysin ,我也尝试了相反的顺序,它没有改变任何东西。

My Maven版本:

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"

我的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>

3 个答案:

答案 0 :(得分:25)

据我所知,pom.xml中存储库的顺序也将决定存储库访问的顺序。

至于在settings.xml中配置存储库,我已经读过存储库的顺序足够有趣地了解了如何访问存储库的顺序。

这里有人解释这种好奇心的帖子:
http://community.jboss.org/message/576851

答案 1 :(得分:20)

在我的案例中,这些答案都不正确..顺序似乎取决于&lt; id&gt;的字母顺序。 tag,是一个任意字符串。因此这个强制回购搜索顺序:

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

答案 2 :(得分:5)

另外,请考虑使用Nexus等存储库管理器并在那里配置所有存储库。