maven repository setting.xml the mirrorof

∥☆過路亽.° 提交于 2019-11-30 07:21:32

Quoting the Maven documentation about mirrors:

To configure a mirror of a given repository, you provide it in your settings file (${user.home}/.m2/settings.xml), giving the new repository its own id and url, and specify the mirrorOf setting that is the ID of the repository you are using a mirror of.

What this means is that mirrorOf points to an existing repository declaration and configures Maven to use that mirror when it attempts to connect the the specified repository.


Let's take an example. You have a project with the following repository defined in your project:

<project>
  ...
  <repositories>
    <repository>
      <id>my-internal-site</id>
      <url>http://myserver/repo</url>
    </repository>
  </repositories>
  ...
</project>

with the following declaration in your settings:

<settings>
  ...
  <mirrors>
    <mirror>
      <id>UK</id>
      <name>UK Central</name>
      <url>http://uk.maven.org/maven2</url>
      <mirrorOf>my-internal-site</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

What this means is that whenever Maven will attempt to download a library from the my-internal-site repository, it will actually not use http://myserver/repo but, instead, use the mirror declaration and download the library from http://uk.maven.org/maven2.

It does not define any order. It just declares where Maven needs to download artifacts in place of the mirrored repository.


Specifying <mirrorOf>central</mirrorOf> tells Maven that you are mirroring the Maven Central repository which is the default location where Maven downloads artifacts from.


As such, using mirrors is often used in enterprise context when you have a central internal repository and every Maven request goes through that repository manager.

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