maven 如何处理多个 <repository> 配置?

How maven handle multiple <repository> configurations?

我对 maven 越来越熟悉了。但还有一些疑问。

我的 pom.xml 中有多个 <repository>

下面是我的 pom.xml<repositories> 部分:

<repositories>
    <repository>
        <id>ibiblio-central-repo</id>
        <layout>default</layout>
        <name>ibiblio-central-repo</name>
        <releases>
            <checksumPolicy>warn</checksumPolicy>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>http://maven.ibiblio.org/maven2/</url>
    </repository>

    <repository>
        <id>oschina-central-repo</id>
        <layout>default</layout>
        <name>oschina-central-repo</name>
        <releases>
            <checksumPolicy>warn</checksumPolicy>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>http://maven.oschina.net/content/groups/public/</url>
    </repository>

    <repository>
        <id>oschina-central-repo-3rd-party</id>
        <layout>default</layout>
        <name>oschina-central-repo-3rd-party</name>
        <releases>
            <checksumPolicy>warn</checksumPolicy>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>http://maven.oschina.net/content/repositories/thirdparty/</url>
    </repository>
</repositories>

How will maven handle these repos when downloading artifacts? Will it search by the declaration order?

作为合并设置的一部分的声明顺序(见下一个答案)。我发现 this JIRA 票证提供了更多详细信息。

Besides the explicitly declared ones, will maven still check the default central repo at http://repo.maven.apache.org/maven2/?

是的,因为它将由 Maven 超级 POM 提供,所有 Maven Pom 的隐含父级(here an official example), unless specified in your settings.xml (if you override the repository id specified in the super POM). You can use the Maven Help Plugin to get the effective settings Maven will apply to your build and the effective pom Maven 实际上(有效)运行。
如记录 hererepositories 元素是继承的。

If something cannot be found within the explicitly configured repo, will maven fallback to the default central repo?

同上。此外,您还可以通过任何已配置的 Maven mirror 影响此机制。例如,您可以将 Maven 重定向到您公司的存储库(见下文),而不是查找默认存储库。

Is it good to use multiple repos? I am kind of worried about inconsistency.

您可能不需要很多已配置的存储库,但如果默认存储库未提供您要查找的依赖项,则可能需要多个。一个好的方法是拥有一个企业 Maven 存储库(即 Artifactory、Nexus)并让您的本地设置仅指向它。然后,以集中(和管理)的方式配置内部 Maven 存储库以指向其他存储库。