这两个设置在Maven中是否相同? [英] Are these two settings same in maven?
问题描述
我想限制Maven仅使用私有/非公共Maven存储库,这两个设置是否具有相同的作用?
I want to limit maven to use only private/not public maven repository, do these two settings have the same effect ?
1.在settings.xml中设置镜像
1.Setting mirror in settings.xml
<mirrors>
<mirror>
<id>my-internal-site</id>
<mirrorOf>*</mirrorOf>
<name>our maven repository</name>
<url>http://myserver/repository</url>
</mirror>
</mirrors>
2.在pom.xml中设置存储库
2.Setting repository in pom.xml
<repositories>
<repository>
<id>my-internal-site</id>
<name>our maven repository</name>
<url>http://myserver/repo</url>
</repository>
</repositories>
同样的要求是,即使内部存储库中不存在某些依赖项,maven也不会访问公共存储库.谢谢
Again the requirement is that maven never goes out to public repositories even if some dependencies are not there on the internal repository. thank you
推荐答案
不,它们没有相同的效果.
No they don't have the same effect.
第二个设置添加一个新的存储库,作为对Central的补充",但不会阻止Maven自己检查Central.
The second setting add a new repository as a "complement" to central but doesn't prevent Maven to check central by itself.
第一个通过使Maven镜像所有存储库请求(通过将mirrorOf
设置为*
)来强制Maven使用单个存储库.这是使用单个存储库的方法.
The first one forces Maven to use a single repository by having it mirror all repository requests (by setting mirrorOf
to *
). This is the way to use a single repository.
因此,您要寻找的是第一个设置,需要在settings.xml
中定义.
What you're looking for is thus the first setting and need to be defined in the settings.xml
.
现在,将公司存储库添加到每台计算机的~/.m2/settings.xml
文件中可能会有些痛苦,而我希望在公司环境中进行的工作是分发并安装包含以下内容的Maven的定制"版本: conf/settings.xml
.这样,人们只需要安装企业"版本,便可以使用了.
Now, adding your corporate repository in the ~/.m2/settings.xml
file of each machine can be a bit painful and what I like to do in a corporate environment is to distribute and install a "customized" version of Maven containing the mirror predefined in conf/settings.xml
. This way, people just have to install the "corporate" version and they are ready to go.
这篇关于这两个设置在Maven中是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!