使用配置文件激活实现多仓库下载
在 Maven 配置文件中配置的 部分定义了 Maven 镜像的设置。
镜像的作用是在构建过程中,将对中央仓库(Central Repository)的访问请求重定向到镜像仓库,从而加速依赖项的下载过程,减轻中央仓库的负载,以及提供备用的下载源。
修改maven的setting文件,设置两个仓库(以此类推,可以添加多个):
<profiles>
<profile>
<!-- id必须唯一 -->
<id>myRepository1</id>
<repositories>
<repository>
<!-- id必须唯一 -->
<id>myRepository1_1</id>
<!-- 仓库的url地址 -->
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<!-- id必须唯一 -->
<id>myRepository2</id>
<repositories>
<repository>
<!-- id必须唯一 -->
<id>myRepository2_1</id>
<!-- 仓库的url地址 -->
<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile> </profiles>
<activeProfiles>
<!-- 激活myRepository1 -->
<activeProfile>myRepository1</activeProfile>
<!-- 激活myRepository2 -->
<activeProfile>myRepository2</activeProfile> </activeProfiles>
因设置的mirrorOf为central,如果我随便设置一个参数,如abc,这时候我们配置的仓库就不起作用了,
这是因为maven默认内置了如下一个仓库,这个默认仓库的id为central,当我们把mirrorOf设置为central时,
maven就会查找有没有id为central的仓库,然后把id为central的仓库地址换成我们标签配置的那个url,这样我们配置的mirror才会起作用。
当然我们也可以把mirrorOf设置为*,表示所有仓库都使用我们配置的这个mirror作为jar包下载地址。