我有Maven2项目 . 除了一个之外的所有依赖项都从公共存储库http://repo.maven.apache.org/maven2/下载 .
但我有1个依赖项,我需要从内部公司的存储库下载(我们使用Sonatype Nexus存储此依赖项) .
另外,我不想在我的内部仓库上创建公共仓库的完整副本 .
此刻我在pom.xml中:
<url>http://maven.apache.org</url>
和
<repositories>
<repository>
<id>thirdparty</id>
<url>http://<my_nexus_server_ip>:8081/nexus/content/repositories/thirdparty</url>
</repository>
</repositories>
因此,在构建期间,我看到了很多垃圾邮件(在这种情况下,第一行是垃圾邮件):
Downloading: http://<my_nexus_server_ip>:8081/nexus/content/repositories/thirdparty/ant/ant/1.6.5/ant-1.6.5.pom
Downloading: http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom
Downloaded: http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom (861 B at 3.2 KB/sec)
我想清楚地指出Maven对于它必须使用内部存储库的依赖,并忽略它用于其他依赖项(并指出其他依赖项Maven2必须使用公共存储库) .
你能帮忙在Maven中实现这样的行为吗?
提前致谢!
2 回答
根据this answer,无法为某些声明的依赖项设置特定的存储库 .
您需要在Nexus中配置公共存储库组,以便在Maven构建中使用唯一的一个,如下所示:
您必须在nexus中设置一个单独的存储库,就像您描述了一个名为
ThirdParty
的存储库,并将此存储库添加到公共存储库组的配置中 . 此外,您需要将一个依赖项上载到该特定存储库中 . 除此之外,您还必须使用 release 和 SNAPSHOT 存储库,这意味着您需要在公司主pom文件中相应地配置您的distributionManagement .