Maven - POM修改來源倉(cāng)庫(kù) 也需要修改pluginRepositories

--- 以下原文
用maven也大幾年了劫流,也一直在用阿里云的中央倉(cāng)庫(kù)庇楞。
不喜歡在maven的settings.xml里改捏卓,更喜歡直接在pom.xml里改极祸,因?yàn)槭躦it管理,小伙伴們拉下來即可怠晴。

然而網(wǎng)上的大部分技術(shù)文章都只會(huì)指導(dǎo)你這么配置:

<repositories>
    <repository>
        <id>aliyun</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

如果你只是配置了repositories遥金,那么你會(huì)發(fā)現(xiàn)在mvn在下載依賴的時(shí)候,一部分從阿里云下載蒜田,一部分還是從默認(rèn)的倉(cāng)庫(kù)(https://repo.maven.apache.org )下載稿械。

# mvn clean install
[INFO] Scanning for projects...
Downloading from aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-starter-parent/2.0.2.RELEASE/spring-boot-s
tarter-parent-2.0.2.RELEASE.pom
Downloaded from aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-starter-parent/2.0.2.RELEASE/spring-boot-st
arter-parent-2.0.2.RELEASE.pom (12 kB at 3.1 kB/s)
...
...
...
[INFO]
[INFO] --------------------------< com.zy:zy-parent >--------------------------
[INFO] Building zy-parent 1.0.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.pom (4.8 kB at 2.2 k
B/s)
...
...
...
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ zy-parent ---
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/3.0/maven-plugin-api-3.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/3.0/maven-plugin-api-3.0.pom (2.3 kB at 1.5 kB/s)
...
...
...
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ zy-parent ---
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/2.2.1/maven-plugin-api-2.2.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/2.2.1/maven-plugin-api-2.2.1.pom (1.5 kB at 1.2 kB/s)
...
...
...
[INFO] Installing E:\work\scratch\lily\src\zy-parent\pom.xml to D:\tools\maven\repo\com\zy\zy-parent\1.0.0-SNAPSHOT\zy-parent-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:25 min
[INFO] Finished at: 2019-11-14T10:13:53+08:00
[INFO] ------------------------------------------------------------------------

原來,只有項(xiàng)目本身的依賴冲粤,走了aliyun這個(gè)repository美莫,maven命令需要的插件(比如clean、install都是maven的插件)梯捕,走的還是默認(rèn)的repository厢呵。

查看maven的官方文檔(http://maven.apache.org/pom.html#Plugin_Repositories ),可以看到pom中除了repositories節(jié)點(diǎn)之外傀顾,還有一個(gè)關(guān)于倉(cāng)庫(kù)的節(jié)點(diǎn)是pluginRepositories:

Repositories are home to two major types of artifacts. The first are artifacts that are used as dependencies of other artifacts. These are the majority of plugins that reside within central. The other type of artifact is plugins. Maven plugins are themselves a special type of artifact. Because of this, plugin repositories may be separated from other repositories (although, I have yet to hear a convincing argument for doing so). In any case, the structure of the pluginRepositories element block is similar to the repositories element. The pluginRepository elements each specify a remote location of where Maven can find new plugins.

所以我們還需要再pom中增加pluginRepositories才可以襟铭。
這也是網(wǎng)上大部分文章里忽略掉的內(nèi)容。短曾。寒砖。。嫉拐。

最終的pom文件如下:

<repositories>
    <repository>
        <id>aliyun</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>aliyun-plugin</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

現(xiàn)在哩都,你可以清空本地maven倉(cāng)庫(kù)中的包,然后再次執(zhí)一下mvn clean install婉徘,看看是不是都走了阿里云的倉(cāng)庫(kù)了茅逮。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市判哥,隨后出現(xiàn)的幾起案子献雅,更是在濱河造成了極大的恐慌,老刑警劉巖塌计,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件挺身,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡锌仅,警方通過查閱死者的電腦和手機(jī)章钾,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門墙贱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人贱傀,你說我怎么就攤上這事惨撇。” “怎么了府寒?”我有些...
    開封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵魁衙,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我株搔,道長(zhǎng)剖淀,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任纤房,我火速辦了婚禮纵隔,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘炮姨。我一直安慰自己捌刮,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開白布舒岸。 她就那樣靜靜地躺著糊啡,像睡著了一般。 火紅的嫁衣襯著肌膚如雪吁津。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天堕扶,我揣著相機(jī)與錄音碍脏,去河邊找鬼。 笑死稍算,一個(gè)胖子當(dāng)著我的面吹牛典尾,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播糊探,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼钾埂,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了科平?” 一聲冷哼從身側(cè)響起褥紫,我...
    開封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎瞪慧,沒想到半個(gè)月后髓考,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡弃酌,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年氨菇,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了儡炼。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡查蓉,死狀恐怖乌询,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情豌研,我是刑警寧澤妹田,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站聂沙,受9級(jí)特大地震影響秆麸,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜及汉,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一沮趣、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧坷随,春花似錦房铭、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至类溢,卻和暖如春凌蔬,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背闯冷。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工砂心, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蛇耀。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓辩诞,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親纺涤。 傳聞我的和親對(duì)象是個(gè)殘疾皇子译暂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容