Maven mirrorOf配置

问题描述:
今天在公司准备搭建一个springboot+activiti的框架,通过pom.xml中引入相关依赖,发现activiti相关的依赖始终无法下载。在中央仓库查找发现这个依赖也存在啊,于是就想到可能是.m2/setting.xml中mirror配置出现的原因。

本地.m2/setting.xml的配置如下:

<mirror>
<id>public</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.i.XX.com:8081/content/groups/public/</url>      
 <name>winxuan-repository</name>
</mirror>

这里配置的是公司的一个私服地址,直接访问这个私服地址,发现里面果然没有activiti相关的依赖包。为什么配置了公司的仓库镜像后,如果找不到相关依赖,难道不会去中央仓库下载么?

通过查看相关资料发现原来是mirrorOf配置引起的原因 mirrorof example:

* = everything
external:* = everything not on the localhost and not file based.
repo,repo1 = repo or repo1
*,!repo1 = everything except repo1

发现如果在<mirrorOf>中配置*,表示当前mirror为所有仓库镜像,所有远程仓库请求地址为当前mirror对应的URL( having it mirror all repository requests)。所以我把此处的mirrorOf改为resp1,此时当前mirror只会拦截仓库resp1的依赖请求,对于其他请求会到远程中央仓库去下载,但下载的速度非常的慢,同时出现连接超时的现象:
这里写图片描述
毕竟中央仓库在国外,连接超时还是很正常的。通过选用阿里云的镜像来解决这个问题。最终setting的配置如下:

<mirrors>
    <mirror>
        <id>public</id>
        <mirrorOf>resp1</mirrorOf>
        <url>http://maven.i.winxuan.com:8081/content/groups/public/</url>
        <name>winxuan-repository</name>
    </mirror>
    <mirror>
        <!--aliyun mirror reponstory -->
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>

<mirrorOf>为center,表示当前镜像为远程中央仓库的镜像。最终pom.xml不再出现小红叉:
这里写图片描述
其他问题:
Setting.xml中repository的配置与pom.xml中repository的配置有什么不同?
Setting.xml中配置repository与pom.xml中配置repository的作用是相同的,都是为了指定多个存储库的使用(you can specify the use of multiple repositories)。但在pom.xml中配置只对当前项目与子项目有用,而在setting.xml中配置为全局性配置,用于所用的项目。

maven相关学习资源:
a:慕课网上maven相关视频讲解
b:博客https://blog.csdn.net/cwh056056/article/category/5915341

  • 7
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值