从 Maven 中的特定存储库下载依赖项

Download a dependency from a specific repository in Maven

我知道这个问题已经被问过很多次了,但我还是找不到解决办法。我有两个 nexus 存储库,我在 settings.xml 中定义了两个镜像,如下所示:

    <mirrors>    
    <mirror>
      <id>nexus_a</id>
      <mirrorOf>nexus_a,nexus_b</mirrorOf>
      <url>https://***</url>
    </mirror>
    <mirror>
      <id>nexus_b</id>
      <mirrorOf>nexus_b</mirrorOf>
      <url>https://***</url>
    </mirror>
    </mirrors>

然后我有两个存储库:

        <repositories>
            <repository>
                <id>nexus_a</id>
                <url>https://nexus-a</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>nexus_b</id>
                <url>https://nexus-b</url>
                <releases>
                    <enabled>true</enabled>
                </releases>                 
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>

然后在我的 pom 中有一个依赖项列表,其中一个应该从 nexus_a 下载,另一个从 nexus_b 下载。 同样在我的 pom 中,我有两个像以前一样的存储库。

感谢任何人的回答。

首先,你的镜像定义有点矛盾,我不明白它们的用途。

其次,您不能选择应该从哪里下载它的依赖项。但我也看不出有什么重要原因。如果您同时定义了两个存储库,Maven 将只查找第一个存储库,如果没有找到任何内容,它将查找第二个存储库。所以除了性能,我看不出有什么缺点。