Maven之阿里雲鏡像倉庫配置--詳解

方式一:全局配置
可以添加阿里雲的鏡像到maven的setting.xml配置中,這樣就不需要每次在pom中,添加鏡像倉庫的配置,在mirrors節點下面添加子節點:


<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public class="hljs-tag"></url>


注:< mirrorOf>可以設置爲哪個中央倉庫做鏡像,爲名爲“central”的中央倉庫做鏡像,寫作< mirrorOf>central< /mirrorOf>;爲所有中央倉庫做鏡像,寫作< mirrorOf>< /mirrorOf>。Maven默認中央倉庫的id 爲 central。id是唯一的。
重要:除非你有把握,否則不建議使用< mirrorOf>
< /mirrorOf>的方式。


setting.xml配置文件位置
114
添加鏡像配置
115
方式二:單項目配置
單項目配置時,需要修改pom文件。pom文件中,沒有mirror元素。在pom文件中,通過覆蓋默認的中央倉庫的配置,實現中央倉庫地址的變更。
修改項目的pom文件:


xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>conifg</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>

<repositories>

<span class="hljs-tag">&lt;<span class="hljs-name">repository</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">id</span>&gt;</span>central<span class="hljs-tag">&lt;/<span class="hljs-name">id</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>aliyun maven<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">url</span>&gt;</span>http://maven.aliyun.com/nexus/content/groups/public/<span class="hljs-tag">&lt;/<span class="hljs-name">url</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">layout</span>&gt;</span>default<span class="hljs-tag">&lt;/<span class="hljs-name">layout</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 是否開啓發布版構件下載 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">releases</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">enabled</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">enabled</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">releases</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 是否開啓快照版構件下載 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">snapshots</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">enabled</span>&gt;</span>false<span class="hljs-tag">&lt;/<span class="hljs-name">enabled</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">snapshots</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">repository</span>&gt;</span>

</repositories>



相關福利:阿里云云產品折扣券:[https://www.aliyun.com/minisite/goods](https://www.aliyun.com/minisite/goods?userCode=28kqeewo
)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章