解决方案:
在网上google得知,maven仓库的优先级为:
本地仓库 > settings文件中配置的profile > pom文件中仓库地址 >settings文件中的mirror
很多时候不同项目之间使用公共的仓库地址,所以有时候我们把公共的仓库提取出来,配置到settings.xml中,
官网对使用mirror有下面的好处:
- There is a synchronized mirror on the internet that is geographically closer and faster
- You want to replace a particular repository with your own internal repository which you have greater control over
- You want to run a repository manager to provide a local cache to a mirror and need to use its URL instead
我觉着就是为了更好、更快、更可控。
配置如下
<mirror>
<id>UK</id>
<name>UK Central</name>
<url>http://uk.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
id必须是唯一的,是mirror在settings文件中唯一标识
mirrorOf很重要,它的意思是:为id为mirrorof值的repository提供镜像,它有一下的几种配置:
- :所有的仓库,所有repository都走mirror配置的url
- external::表示任何不在localhost和文件系统中的远程库
- r1,r2:表示r1库或者r2库
- *,!r1:除了r1库之外的任何远程库
在使用mirror的时候,需要注意的是一个repository只能有一个mirror
因此即使我在pom文件指定了repository,虽然pom文件的repository优先级比mirror优先级高,但是mirrorOf的*已经把所有repository都替换了,所以pom文件中的repository不起作用。