Spring-boot的maven倉庫配置阿里雲鏡像以及setting.xml和pom.xml的優先級


阿里雲鏡像地址

https://maven.aliyun.com/mvn/guide

pom.xml

在pom.xml文件中project結點下最后面,有個repositories結點,更改里面的url結點中的內容即可

 比如說,我是用public倉庫

<repositories>
    <repository>
        <id>aliyun</id>
        <name>AliYun</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </repository>
</repositories>

 這樣修改即可

 一個java項目通過maven自動下載依賴時,會讀取三個配置文件,分別是

  • 項目下的pom.xml 文件
  • 家目錄下的.m2/settings.xml 與
  • maven 全局配置settings.xml

 后面兩者不難理解,就像linux下的用戶一樣,有一個/etc/profile ,用戶用目錄下還有一個.bash_profile 文件是一樣的

 用戶自定義配置會覆蓋全局配置

 所以三者的級先是 pom.xml  > /home_dir/.m2/settings.xml > /maven_dir/conf/settings.xml 

 如果要全局修改,需要在mavn3/conf下找到setting.xml來修改

mirror和repository的區別

  • mirror相當於一個攔截器,它會攔截maven對remote repository的相關請求,把請求里的remote repository地址,重定向到mirror里配置的地址

 

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
     <mirror>
        <id>aliyun</id>
        <mirrorOf>public</mirrorOf>
        <name>AliYun</name>
        <url>https://maven.aliyun.com/repository/public</url>
      </mirror>
    </mirrors>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM