Maven Mirror镜像

maven Mirror镜像

mirror相当于一个拦截器,它会拦截maven对remote repository的相关请求,把请求里的remote repository地址,重定向到mirror里配置的地址。
1. 没有配置mirror

 

 

2. 配置mirror

 

3. mirrorOf
<mirrorOf></mirrorOf>标签里面放置的是要被镜像的Repository ID。为了满足一些复杂的需求,Maven还支持更高级的镜像配置:

<mirrorOf>*</mirrorOf> 
匹配所有仓库请求,即将所有的仓库请求都转到该镜像上
<mirrorOf>repo1,repo2</mirrorOf> 
将仓库repo1和repo2的请求转到该镜像上,使用逗号分隔多个远程仓库。 
<mirrorOf>*,!repo1</miiroOf> 
匹配所有仓库请求,repo1除外,使用感叹号将仓库从匹配中排除。

配置演示

<settings>
...
  <mirrors>
    <mirror>
      <id>maven-net-cn</id>
      <name>Maven China Mirror</name>
      <url>http://maven.net.cn/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
...
</settings>

 这里唯一需要解释的是,这里我们配置central的镜像,我们也可以配置一个所有仓库的镜像,以保证该镜像是Maven唯一使用的仓库

推荐几个镜像站点

1、阿里云镜像(阿里云的镜像站(首推,新站,速度暴快))

<mirror>
  <id>nexus-aliyun</id>
  <name>Nexus aliyun</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 
  <mirrorOf>central</mirrorOf> 
</mirror>

 

2、maven官方2号镜像(国外)

<mirror>
    <id>repo2</id>
    <name>Mirror from Maven Repo2</name>
    <url>http://repo2.maven.org/maven2/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

 

3、maven的UK镜像

<mirror>
    <id>ui</id>
    <name>Mirror from UK</name>
    <url>http://uk.maven.org/maven2/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

 

4、JBoss 镜像

<mirror>
    <id>jboss-public-repository-group</id>
    <mirrorOf>central</mirrorOf>
    <name>JBoss Public Repository Group</name>
    <url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>

 

posted @ 2022-01-21 10:36  IT6889  阅读(680)  评论(0编辑  收藏  举报