在Maven中使用多个存储库 [英] Using multiple repositories in Maven
问题描述
我有一个使用内部存储库和中央存储库的项目.有没有一种方法可以配置settings.xml,以便我可以同时使用两者而不是一个?当我添加
I have a project that uses an internal repository and the central repository. Is there a way I can configure the settings.xml such that I can use both instead of just one? When I added
<mirrors>
<mirror>
<id>MY ID</id>
<url>MY URL</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
在settings.xml中,我可以查看自己的内部存储库,但它会覆盖中央存储库.
in settings.xml, I can look into my own internal repository but it overrides the central repository.
我确定这是Maven新手经常遇到的问题.
I am sure this is a commonly encountered problem for people new to Maven.
推荐答案
有几种方法可以做到这一点.
There are a few of ways to do this.
最好的IMO是让本地存储库服务器充当Maven Central的代理. Nexus和Artifactory均可立即使用.如果您使用的是Apache或其他Web服务器,则应进行切换.
The best, IMO, is to have your local repository server act as a proxy for Maven Central. Both Nexus and Artifactory do this out of the box. If you're using Apache or another web server, you should switch.
您还可以更新设置,从镜像中排除目标服务器:
You can also update your settings exclude the target server from your mirror:
<mirrorOf>*,!MyOtherRepository</mirrorOf>
如果您有多个本地存储库服务器,则可以使用此方法,但是我认为您不能以这种方式排除 central :默认情况下,Maven在中央查找工件,并且您的服务器充当支架-为此.
This works if you have multiple local repository servers, but I don't think you can exclude central this way: by default, Maven looks for artifacts in central, and your server acts as a stand-in for it.
这将在您的POMS中保留显式存储库条目,这些条目引用了本地存储库.如果您的本地存储库只是为您的工件服务,那么这可能是第二件事(特别是如果您使用包含存储库规范的父POM).
Which leaves explicit repository entries in your POMS, which reference the local repository. If your local repository just serves your artifacts, this might be the second-simplest thing to do (especially if you use a parent POM that holds the repository specification).
这篇关于在Maven中使用多个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!