maven中央倉庫訪問速度太慢的解決辦法


方法一:修改settings.xml

eclipse中集成的maven的settings.xml文件,找了半年也沒找到,我們放棄eclipse中的maven,下一個最新的maven,並在eclipse中配置該maven中的settings.xml:

 

 

eclipse在第一次編譯maven項目時,會下載很多maven的插件,如果什么都沒做的話,就會從默認的官網倉庫地址下載。

為了加快訪問速度,我們要把官網倉庫地址替換為國內訪問速度較快的鏡像地址。

這里用的是:http://maven.aliyun.com/nexus/content/groups/public/ 這個地址,

 

在settings.xml中找到

 

 然后在注釋外邊,mirrors標簽里面配一個mirror:

<mirror>
      <id>mirrorId</id>
      <mirrorOf>central</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>

 

如此中央倉庫(central)的默認地址就被aliyun的地址攔截了。

 

方法二:直接在pom.xml上改

    <repositories>
        <repository>
            <id>aliyun</id>
            <name>aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
            <pluginRepository>
            <id>aliyun</id>
            <name>aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            </pluginRepository>
        </pluginRepositories>

 

加上這兩段即可。

 

關於repository和mirror的關系,maven會先從repository讀倉庫信息,然后去settings.xml中找一下mirror里面有沒有同名的,如果有就用同名mirror的地址,沒有則使用repository中的地址。


免責聲明!

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



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