美文网首页程序员程序员技术专区-Maven系列
IDEA 中动态配置Maven的mirror镜像源

IDEA 中动态配置Maven的mirror镜像源

作者: 沐之轻语 | 来源:发表于2020-08-24 22:47 被阅读0次

1.问题    

在公司研发过程中遇到一个问题, 在公司开发环境中使用私服的镜像, 在家里的话,无法链接公司私服, 需要用阿里云的镜像,每次切换 settings.xml 比较麻烦,  如果能够动态切换 mirror 的配置,就比较棒了. 

于是查询了部分资料,发现 maven 的mirror 可以使用变量,解决这个问题

2.修改settings.xml 的 mirros 如下

<mirrors>

        <mirror>

                <id>aliyun</id>

                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

                <mirrorOf>${aliyun}</mirrorOf>

        </mirror>

        <mirror>

                <id>公司私服</id>

                <mirrorOf>${公司私服}</mirrorOf>

                <url>https://nexus.***.cn/content/groups/public</url>

        </mirror>

</mirrors>

3.在idea 中动态修改指定镜像

    3.1 Preferneces  中找到maven 修改如下参数

    maven 打包使用不同镜像: 

            mvn help:effective-settings -D你的mirrorId=central

    -D你的<mirrorOf>中的变量名=* # 表示全部代   

   -D你的<mirrorOf>中的变量名=central # 表示代理central#

  我的设置-Daliyun=central # 表示指定阿里云代理central

    3.2 如图所示

4.其他:

    如果有其他问题,麻烦私聊我处理

相关文章

网友评论

    本文标题:IDEA 中动态配置Maven的mirror镜像源

    本文链接:https://www.haomeiwen.com/subject/inpojktx.html