• 怎么配置Maven的镜像仓库才是正确的


      

    目录

    前言

    第一种

     第二种

    总结 


    前言

            我们在使用Maven的时候都会去更改镜像仓库,我在网上看到的更多是配置在下的,还有一种是配置在下。好奇两种配置有什么区别,下面让我们深入探讨探讨。

    第一种

    我们先看下网上配置最多的方式,接下来我用阿里的库进行演示,我将在标签里添加如下配置:

    1. <mirror>
    2. <id>aliyunmavenid>
    3. <mirrorOf>*mirrorOf>
    4. <name>阿里云公共仓库name>
    5. <url>https://maven.aliyun.com/repository/publicurl>
    6. mirror>

    接下来在pom写一个不存在的依赖坐标: 

      

     用命令下载看下:

     

    通过上面的图片可以看到它去阿里仓库下载,但是没找到就抛异常了!接下来我们看下第二种。 

     第二种

    我将上面添加在里的配置删掉,然后在下添加如下配置:

    1. <profile>
    2. <id>aliyunRepositoryid>
    3. <repositories>
    4. <repository>
    5. <id>aliyunid>
    6. <url>https://maven.aliyun.com/repository/centralurl>
    7. <releases>
    8. <enabled>trueenabled>
    9. releases>
    10. <snapshots>
    11. <enabled>trueenabled>
    12. snapshots>
    13. repository>
    14. repositories>
    15. <pluginRepositories>
    16. <pluginRepository>
    17. <id>aliyun-pluginid>
    18. <url>https://maven.aliyun.com/repository/centralurl>
    19. <releases>
    20. <enabled>trueenabled>
    21. releases>
    22. <snapshots>
    23. <enabled>trueenabled>
    24. snapshots>
    25. pluginRepository>
    26. pluginRepositories>
    27. profile>

    需要在配置文件的末尾添加如下配置,以便激活使用以上的仓库:

    1. <activeProfiles>
    2. <activeProfile>aliyunRepositoryactiveProfile>
    3. activeProfiles>

     跟上面一样在cmd窗口用命令下载:

    通过以上的图片可以明显的看到,它先是去阿里的仓库寻找,没找到后就去中央仓库寻找,还是没找到便抛出了异常!这下区别就很明显了!

    总结 

            通过以上的对比,如果你想做到既能让自己配置的远程库生效又想让中央仓库生效的话可以考虑第二种配置!大家也知道是可以配置多个的,这个时候大家可能会认为第一个仓库找不到的时候便会去第二个仓库找,但并非如此,只有当第一个仓库连接不上了才会去第二个仓库!

    🥇原创不易,还希望各位大佬支持一下!
    👍点赞,你的认可是我创作的动力 !
    🌟收藏,你的青睐是我努力的方向!
    ✏️评论,你的意见是我进步的财富! 

  • 相关阅读:
    什么是serialVersionUID?serialVersionUID详解
    Taro小程序富文本解析4种方法
    【Pytorch】深度学习之优化器
    探讨基于IEC61499开发类似LabVIEW图形编程工具
    【云原生-白皮书】简章2:深入理解DevOps+微服务
    Go-知识error
    mitmproxy 抓包神器-8.阿里云/腾讯云服务器无法访问mitmweb问题解决?
    吴恩达机器学习week2实验答案Practice Lab Linear Regression【C1_W2_Linear_Regression】
    AC8015笔记
    2022亚太CDN峰会|九州云邀你一同探索5G MEC边缘计算发展
  • 原文地址:https://blog.csdn.net/qq_38238956/article/details/126688994