Maven mirror warehouse configuration (multi-mirror automatic switching)

When you use IDEA, you will encounter such a problem, that is, when downloading source code and resource documents, some mirror warehouses do not have source code and resource documents, and then the download will fail.
At this time, the addresses of multiple mirror warehouses are needed.

Attaching my own config file:

  <mirrors>
    <!-- 阿里云仓库 -->
    <!-- 中央仓库在中国的镜像 -->
   <mirror>
       <id>alimaven</id>
       <name>aliyun maven</name>
       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
       <mirrorOf>central</mirrorOf>
   </mirror>

   <mirror>
       <id>central</id>
       <name>Maven Repository Switchboard</name>
       <url>http://repo1.maven.apache.org/maven2/</url>
       <mirrorOf>*</mirrorOf>
   </mirror>
   <!-- sping  -->
   <mirror>
       <id>sprintio</id>
       <mirrorOf>central</mirrorOf>
       <name>Human Readable Name for this Mirror.</name>
       <url>https://repo.spring.io/libs-snapshot/</url>
       <mirrorOf>*</mirrorOf>
   </mirror>
   
   <!-- google  -->
   <mirror>
       <id>google</id>
       <name>google maven</name>
       <url>https://maven.google.com/</url>
       <mirrorOf>*</mirrorOf>
   </mirror>


    <mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>
  </mirrors>

There is a mirrorOf tag in the mirror tag,
note: the value is center, indicating that the current mirror is the mirror of the remote central warehouse

mirrorOf可以理解“为某个仓库(repository)的做镜像”,填写的是repostoryId。
”*“ 的意思就是匹配所有的仓库(repository)。
相当于一个拦截器,它会拦截maven对remote repository的相关请求,把请求里的remote repository地址,	
重定向到mirror里配置的地址。apache-maven的settings.xml不做任何配置时是有默认的仓库的,这个仓库就是central仓库,默认值是https://repo.maven.apache.org/maven2/,我们可以配置mirrorOf=central只镜像默认的central仓库。如果你只配置了mirrorOf=”my-repo-id“没有配置central或*,那么请求maven会判断,首先在默认的central仓库https://repo.maven.apache.org/maven2/找依赖,如果找不到就去my-repo-id对应的仓库找,遍历所有仓库后找不到就报错。

Guess you like

Origin blog.csdn.net/qq_16733389/article/details/131934617