Maven mirrorOf配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31071543/article/details/81564562

问题描述:
今天在公司准备搭建一个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

猜你喜欢

转载自blog.csdn.net/qq_31071543/article/details/81564562