如果连结伺服器关闭,我该如何配置Maven来存取Maven Central? [英] How do I configure maven to access maven central if nexus server is down?

查看:102
本文介绍了如果连结伺服器关闭,我该如何配置Maven来存取Maven Central?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置我的构建,以便在我们的联系服务器无法访问时,它会自动尝试从maven中央下载工件.我在settings.xml中有以下内容,而且不确定如何更改(即使可能的话).

I would like to setup my build such that it automatically attempts to download an artifact from maven central iff our nexus server is unreachable. I have the following in settings.xml and I'm not sure how to change it (if even possible).

<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://mynexus</url>
     <releases><enabled>true</enabled></releases>
     <snapshots><enabled>true</enabled></snapshots>
   </repository>
 </repositories>
 <pluginRepositories>
   <pluginRepository>
     <id>central</id>
     <url>http://mynexus</url>
     <releases><enabled>true</enabled></releases>
     <snapshots><enabled>true</enabled></snapshots>
   </pluginRepository>
 </pluginRepositories>
</profile>
</profiles>

<activeProfiles>
   <activeProfile>nexus</activeProfile>
</activeProfiles>

推荐答案

要使用存储库管理器(包括Nexus),您需要定义一个mirrorOf *元素,该元素将拦截所有存储库URL并将其发送给Nexus解析度.在Maven2和3中,不能在概要文件中配置mirrorOf元素.这意味着在不更改设置的情况下没有简单的方法来回切换.

In order to use a repository manager (Nexus included) you need to have a mirrorOf * element defined that will intercept all the repository urls and send them to Nexus for resolution. In Maven2 and 3, the mirrorOf element is not able to be configured in a profile. This means there is no easy way to flip back and forth without changing your settings.

您需要注释掉镜像"部分,然后停用Nexus配置文件,以使Maven恢复为标准行为.

You would need to comment out the mirrors section and then deactivate the Nexus profile to have Maven revert back to standard behavior.

幸运的是,尽管Nexus非常稳定,并且永远都不会崩溃.

Fortunately though Nexus is very stable and it should never go down.

这篇关于如果连结伺服器关闭,我该如何配置Maven来存取Maven Central?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆