最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談Maven 項目中依賴的搜索順序

 更新時間:2018年09月27日 14:30:23   作者:polly  
這篇文章主要介紹了淺談Maven 項目中依賴的搜索順序,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

網(wǎng)上有很多關(guān)于maven項目中mirror、profile、repository的搜索順序的文章,說法不一。官方文檔并沒有找到相關(guān)的說明,鑒于此,我抽時間做了一個驗證。

依賴倉庫的配置方式

maven項目使用的倉庫一共有如下幾種方式:

  1. 中央倉庫,這是默認的倉庫
  2. 鏡像倉庫,通過 sttings.xml 中的 settings.mirrors.mirror 配置
  3. 全局profile倉庫,通過 settings.xml 中的 settings.repositories.repository 配置
  4. 項目倉庫,通過 pom.xml 中的 project.repositories.repository 配置
  5. 項目profile倉庫,通過 pom.xml 中的 project.profiles.profile.repositories.repository 配置
  6. 本地倉庫

如果所有配置都存在,依賴的搜索順序就會變得異常復(fù)雜。

分析依賴搜索順序

先從最簡單開始,慢慢增加配置,查看有什么變化。

準備測試環(huán)境

安裝jdk、maven。

使用如下命令創(chuàng)建測試項目:

復(fù)制代碼 代碼如下:
yes | mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp  -DinteractiveMode=true -DgroupId=com.pollyduan -DartifactId=myweb -Dversion=1.0 -Dpackage=com.pollyduan

創(chuàng)建完成后,為了避免后續(xù)測試干擾,先執(zhí)行一次compile。

cd myweb
mvn compile

最后,修改 pom.xml 文件,將 junit版本號改為 4.12 。我們要使用這個jar來測試依賴的搜索順序。

默認情況

首先確保junit4.12不存在:

rm -rf ~/.m2/repository/junit/junit/4.12

默認情況下沒有配置任何倉庫,也就是說,既沒改 $M2_HOME/conf/settings.xml 也沒有添加 ~/.m2/settings.xml

執(zhí)行編譯,查看日志中拉取junit的倉庫。

mvn compile

...
Downloaded from central: https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12.pom (24 kB at 11 kB/s)

可以看出,默認是從 central 中央倉庫拉取的jar.

配置鏡像倉庫 settings_mirror

創(chuàng)建 ~/.m2/setttings.xml ,內(nèi)容如下:

<settings>
 <mirrors>
  <mirror>
   <id>settings_mirror</id>
   <url>https://maven.aliyun.com/repository/public</url>
   <mirrorOf>central</mirrorOf>
  </mirror>
 </mirrors>
</settings>

重新測試:

rm -rf ~/.m2/repository/junit/junit/4.12
mvn compile

在日志中查看下載依賴的倉庫:

復(fù)制代碼 代碼如下:
Downloaded from settings_mirror: https://maven.aliyun.com/repository/public/junit/junit/4.12/junit-4.12.pom (24 kB at 35 kB/s)

可以看出,是從 settings_mirror 中下載的jar

結(jié)論:settings_mirror 的優(yōu)先級高于 central

配置pom中的倉庫 pom_repositories

在 project 中增加如下配置:

<repositories>
 <repository>
  <id>pom_repositories</id>
  <name>local</name>
  <url>http://10.18.29.128/nexus/content/groups/public/</url>
  <releases>
   <enabled>true</enabled>
  </releases>
  <snapshots>
   <enabled>true</enabled>
  </snapshots>
 </repository>
</repositories>

由于我們改變了id的名字,所以倉庫地址無所謂,使用相同的地址也不影響測試。

執(zhí)行測試:

rm -rf ~/.m2/repository/junit/junit/4.12
mvn compile

在日志中查看下載依賴的倉庫:

復(fù)制代碼 代碼如下:
Downloaded from pom_repositories: http://10.18.29.128/nexus/content/groups/public/junit/junit/4.12/junit-4.12.pom (24 kB at 95 kB/s)

從顯示的倉庫id可以看出:

  • jar 是從 pom_repositories 中下載的。
  • pom_repositories 優(yōu)先級高于 settings_mirror

配置全局profile倉庫 settings_profile_repo

在 ~/.m2/settings.xml 中 settings 的節(jié)點內(nèi)增加:

<profiles>
 <profile>
 <id>s_profile</id>
 <repositories>
  <repository>
   <id>settings_profile_repo</id>
   <name>netease</name>
   <url>http://mirrors.163.com/maven/repository/maven-public/</url>
   <releases>
    <enabled>true</enabled>
   </releases>
   <snapshots>
    <enabled>true</enabled>
   </snapshots>
  </repository>
 </repositories>
 </profile>
</profiles>

執(zhí)行測試:

rm -rf ~/.m2/repository/junit/junit/4.12
mvn compile -Ps_profile

在日志中查看下載依賴的倉庫:

復(fù)制代碼 代碼如下:
Downloaded from settings_profile_repo: http://mirrors.163.com/maven/repository/maven-public/junit/junit/4.12/junit-4.12.pom (24 kB at 63 kB/s)

從顯示的倉庫id可以看出:

  • jar 是從 settings_profile_repo 中下載的。
  • settings_profile_repo 優(yōu)先級高于 settings_mirror。
  • settings_profile_repo 優(yōu)先級高于 pom_repositories 。

配置項目profile倉庫 pom_profile_repo

<profiles>
 <profile>
  <id>p_profile</id>
  <repositories>
   <repository>
    <id>pom_profile_repo</id>
    <name>local</name>
    <url>http://10.18.29.128/nexus/content/groups/public/</url>
    <releases>
     <enabled>true</enabled>
    </releases>
    <snapshots>
     <enabled>true</enabled>
    </snapshots>
   </repository>
  </repositories>
 </profile>
</profiles>

執(zhí)行測試:

rm -rf ~/.m2/repository/junit/junit/4.12
mvn compile -Ps_profile,p_profile
mvn compile -Pp_profile,s_profile

在日志中查看下載依賴的倉庫:

復(fù)制代碼 代碼如下:
Downloaded from settings_profile_repo: http://mirrors.163.com/maven/repository/maven-public/junit/junit/4.12/junit-4.12.pom (24 kB at 68 kB/s)

從顯示的倉庫id可以看出:

  • jar 是從 settings_profile_repo 中下載的
  • settings_profile_repo 優(yōu)先級高于 pom_profile_repo

進一步測試:

rm -rf ~/.m2/repository/junit/junit/4.12
mvn compile -Pp_profile

在日志中查看下載依賴的倉庫:

復(fù)制代碼 代碼如下:
Downloaded from pom_profile_repo: http://10.18.29.128/nexus/content/groups/public/junit/junit/4.12/junit-4.12.pom (24 kB at 106 kB/s)

從顯示的倉庫id可以看出:

  • jar 是從 settings_profile_repo 中下載的
  • pom_profile_repo 優(yōu)先級高于 pom_repositories

最后確認 local_repo 本地倉庫 ~/.m2/repository

這不算測試了,只是一個結(jié)論,可以任意測試。

只要 ~/.m2/repository 中包含依賴,無論怎么配置,都會優(yōu)先使用local本地倉庫中的jar.

最終結(jié)論

  • settings_mirror 的優(yōu)先級高于 central
  • settings_profile_repo 優(yōu)先級高于 settings_mirror
  • settings_profile_repo 優(yōu)先級高于 pom_repositories
  • settings_profile_repo 優(yōu)先級高于 pom_profile_repo
  • pom_profile_repo 優(yōu)先級高于 pom_repositories
  • pom_repositories 優(yōu)先級高于 settings_mirror

通過上面的比較得出完整的搜索鏈:

local_repo > settings_profile_repo > pom_profile_repo > pom_repositories > settings_mirror > central

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringCloud環(huán)境搭建過程之Rest使用小結(jié)

    SpringCloud環(huán)境搭建過程之Rest使用小結(jié)

    這篇文章主要介紹了SpringCloud環(huán)境搭建之Rest使用,本文通過實例代碼圖文相結(jié)合給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • Java開發(fā)環(huán)境配置及Vscode搭建過程

    Java開發(fā)環(huán)境配置及Vscode搭建過程

    今天通過圖文并茂的形式給大家介紹Java開發(fā)環(huán)境配置及Vscode搭建過程,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2021-07-07
  • 用java實現(xiàn)在txt文本中寫數(shù)據(jù)和讀數(shù)據(jù)的方法

    用java實現(xiàn)在txt文本中寫數(shù)據(jù)和讀數(shù)據(jù)的方法

    今天小編就為大家分享一篇用java實現(xiàn)在txt文本中寫數(shù)據(jù)和讀數(shù)據(jù)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • 關(guān)于thymeleaf判斷對象是否為空的相關(guān)邏輯處理

    關(guān)于thymeleaf判斷對象是否為空的相關(guān)邏輯處理

    這篇文章主要介紹了關(guān)于thymeleaf判斷對象是否為空的相關(guān)邏輯處理,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • 詳解JavaWeb中的 Listener

    詳解JavaWeb中的 Listener

    JavaWeb里面的listener是通過觀察者設(shè)計模式進行實現(xiàn)的。下面通過本文給大家詳細介紹javaweb中的listener,感興趣的朋友一起看看吧
    2016-09-09
  • Spring?Data?JPA注解Entity使用示例詳解

    Spring?Data?JPA注解Entity使用示例詳解

    這篇文章主要為大家介紹了Spring?Data?JPA注解Entity使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • mybatis中mapper.xml文件的常用屬性及標簽講解

    mybatis中mapper.xml文件的常用屬性及標簽講解

    這篇文章主要介紹了mybatis中mapper.xml文件的常用屬性及標簽講解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • netty-grpc一次DirectByteBuffer內(nèi)存泄露問題

    netty-grpc一次DirectByteBuffer內(nèi)存泄露問題

    這篇文章主要介紹了netty-grpc一次DirectByteBuffer內(nèi)存泄露問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • 2個java希爾排序示例

    2個java希爾排序示例

    java希爾排序示例,希爾排序是插入排序的一種類型,也可以用一個形象的叫法縮小增量法,需要的朋友可以參考下
    2014-05-05
  • 詳解Java中的sleep()和wait()的區(qū)別

    詳解Java中的sleep()和wait()的區(qū)別

    這篇文章主要介紹了詳解Java中的sleep()和wait()的區(qū)別的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-09-09

最新評論

友谊县| 峨眉山市| 汝阳县| 清流县| 德江县| 察雅县| 长丰县| 朔州市| 安溪县| 岑溪市| 茶陵县| 金山区| 东明县| 华池县| 延长县| 金乡县| 新巴尔虎右旗| 临朐县| 金川县| 建宁县| 左权县| 德保县| 新沂市| 乌恰县| 英超| 罗江县| 奉节县| 扎赉特旗| 富川| 麦盖提县| 武定县| 双辽市| 康保县| 顺昌县| 伊宁市| 五指山市| 安庆市| 贵溪市| 图们市| 襄汾县| 长沙县|