Maven中央仓库与镜像

1、Maven的中央仓库地址默认是:https://repo.maven.apache.org/maven2/,可以通过修改settings.xml文件来修改默认的中央仓库地址:

<profile>
  <id>repository-profile</id>
  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <layout>default</layout>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>
  </repositories>
</profile>

要注意的是如果修改的是中央仓库地址,那么repository下面的id标签值一定得是central,此外,还需要激活这个profile才能生效,这里的标签值就是profile标签下面的id标签值

<activeProfiles>
	<activeProfile>repository-profile</activeProfile>
</activeProfiles>

2、Maven的镜像是指如果仓库X可以提供仓库Y存储的所有内容,那么就可以认为X是Y的一个镜像,也就是说任何一个可以从仓库Y获得的依赖,都能够从它的镜像中获取。比如阿里的Maven仓库http://maven.aliyun.com/nexus/content/groups/public就可以理解为是中央仓库https://repo.maven.apache.org/maven2/在中国的镜像,由于地理位置的因素,该镜像往往能够提供比中央仓库更快的服务。要为一个仓库配置镜像只需要修改settings.xml文件,如下,其中的mirrorOf标签值就是仓库的id标签值,中央仓库就是默认就是central,表示这是为中央仓库配置的镜像,以后所有的依赖下载都会从这个镜像中进行下载。

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

 

转载于:https://my.oschina.net/u/3438627/blog/903077

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值