Are these two settings same in maven?

删除回忆录丶 提交于 2019-12-06 03:38:35

问题


I want to limit maven to use only private/not public maven repository, do these two settings have the same effect ?

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.Setting repository in pom.xml

<repositories>
    <repository>
      <id>my-internal-site</id>
      <name>our maven repository</name>
      <url>http://myserver/repo</url>
    </repository>
  </repositories>

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


回答1:


No they don't have the same effect.

The second setting add a new repository as a "complement" to central but doesn't prevent Maven to check central by itself.

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.

What you're looking for is thus the first setting and need to be defined in the 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.




回答2:


No, they mean different things:

In the first example, you said that the given repository is a mirror of all repositories, including the official one.

In the second example, you simply add a new repository. In case a dependency is not found in the local repository, Maven will then look in this repository after having searched in the official repository.

Thus, to force the usage of an internal repository, you must configure the mirror in your settings.xml file.

This is explained in the official documentation of Maven.



来源:https://stackoverflow.com/questions/2325730/are-these-two-settings-same-in-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!