Maven配置profiles同时使用多个镜像仓库

在Idea中使用效果:

具体settings.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
    <!--本地仓库路径-->
    <localRepository>/Users/veronica/dev/maven/localRepository</localRepository>
 
    <!--注意:mirrorOf千万别为*,建议为profile的id-->
    <mirrors>
        <mirror>
            <id>aliyun-nexus</id>
            <name>aliyun-nexus</name>
            <mirrorOf>aliyun</mirrorOf>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>
        <mirror>
            <id>huawei-nexus</id>
            <name>huawei-nexus</name>
            <mirrorOf>huawei</mirrorOf>
            <url>https://mirrors.huaweicloud.com/repository/maven/</url>
        </mirror>
    </mirrors>
 
    <profiles>
        <profile>
            <id>aliyun</id>
            <repositories>
                <repository>
                    <id>aliyun-nexus</id>
                    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>aliyun-nexus</id>
                    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <profile>
            <id>huawei</id>
            <repositories>
                <repository>
                    <id>huawei-nexus</id>
                    <url>https://mirrors.huaweicloud.com/repository/maven/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>huawei-nexus</id>
                    <url>https://mirrors.huaweicloud.com/repository/maven/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
 
    <!--设置默认配置文件-->
    <activeProfiles>
        <activeProfile>aliyun</activeProfile>
    </activeProfiles>
 
</settings>

我是用aliyun跟huawei做的例子,可以根据自己的需要去改,我是公司内网repository+aliyun这样不在公司时便可以使用aliyun

未经允许不得转载:鹞之神乐 » Maven配置profiles同时使用多个镜像仓库

赞 (0) 打赏

评论

6+8=

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏