Maven配置多个远程仓库的实现方法

起因

由于公司原因,很多jar包都是内部开源,外部非开源情况,所以很多jar包都在aliyun的远程仓库中找不到。但是又因为回家后,自己写的很多demo都是用的一些公司仓库里没有的jar。所以就想着配置多个Maven仓库镜像地址,从而解决反复切换仓库一问题。

<mrrior></mrrior>配置多个镜像问题
这里必须要提醒!mrrior标签配置多个,生效的只有第一个!只有第一个仓库无法访问的时候,才会使用第二个。注意是无法访问的时候,如果能访问,但是仓库中没有你要找的包,他不会去访问第二个仓库!

<profile></profile>配置多镜像
这里推荐使用profile属性进行多镜像配置。

<profiles>
    <profile>
        <!-- id必须唯一 -->
        <id>aliyunRepository</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>companyRepository</id>
        <repositories>
            <repository>
                <!-- id必须唯一 -->
                <id>myRepository2_1</id>
                <!-- 仓库的url地址 -->
                <url>你们另一个仓库的地址</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
    </profile>
  </profiles>

    <activeProfiles>
    <!-- 激活myRepository2 -->
    <activeProfile>companyRepository</activeProfile>
    <!-- 激活myRepository1 -->
    <activeProfile>aliyunRepository</activeProfile>
  </activeProfiles>
原文地址:https://www.cnblogs.com/panchanggui/p/14704334.html