Maven 2 maven为某些依赖项设置另一个存储库
我有一个Maven2项目。除一个依赖项外,所有依赖项都是从公共存储库下载的 但我有一个依赖项,需要从公司内部的存储库下载(我们使用Sonatype Nexus来存储这个依赖项) 此外,我不想在我的内部回购协议上创建公共回购协议的完整副本 此时,我在pom.xml中看到:Maven 2 maven为某些依赖项设置另一个存储库,maven-2,dependencies,dependency-management,repository,Maven 2,Dependencies,Dependency Management,Repository,我有一个Maven2项目。除一个依赖项外,所有依赖项都是从公共存储库下载的 但我有一个依赖项,需要从公司内部的存储库下载(我们使用Sonatype Nexus来存储这个依赖项) 此外,我不想在我的内部回购协议上创建公共回购协议的完整副本 此时,我在pom.xml中看到: <url>http://maven.apache.org</url> http://maven.apache.org 及 第三方 http://:8081/nexus/content/reposit
<url>http://maven.apache.org</url>
http://maven.apache.org
及
第三方
http://:8081/nexus/content/repositories/thirdparty
因此,在构建过程中,我看到很多垃圾信息(在本例中,第一行是垃圾):
下载:http://:8081/nexus/content/repositories/thirdparty/ant/ant/1.6.5/ant-1.6.5.pom
下载:http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom
下载:http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom (每秒3.2 KB时为861 B)
我想明确指出Maven必须使用内部存储库来处理哪个依赖项,而忽略其他依赖项(并指出Maven2必须使用公共存储库来处理其他依赖项)
您能帮助在Maven中实现这种行为吗
提前谢谢 您需要将Nexus中的公共存储库组配置为Maven版本中唯一使用的组,如下所示:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
关系
*
http://localhost:8081/nexus/content/groups/public
关系
中心的
http://central
真的
真的
中心的
http://central
真的
真的
关系
您必须在nexus中设置一个单独的存储库,就像您描述的名为
ThirdParty
的回购一样,并将此存储库添加到公共存储库组的配置中。此外,您需要将一个依赖项上载到该特定存储库中。除此之外,您还必须使用发行版和快照存储库,这意味着您需要在公司主pom文件中相应地配置分发管理,无法为某些已声明的依赖项设置特定的存储库。我们使用Sonatype,正如我在上述问题中所述。我们将其用于我们的私有组件管理。但是我们的项目有很多外部依赖项,Maven可以从公共存储库下载这些依赖项。我需要告诉Maven只对1个依赖项使用我们的内部存储库,对其他依赖项使用公共存储库。问题在Maven日志中。我不想看到Maven试图从错误的存储库下载依赖项(我们的包来自公共repo,外部包来自内部repo)。我认为这就像Maven配置问题一样。我网站上的误解。相应地更新了答案。
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)
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>