欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java Maven settings.xml中私有倉庫配置詳解

 更新時間:2021年10月12日 11:51:38   投稿:BJT  
這篇文章主要介紹了詳解Maven settings.xml配置,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

Maven setting中私有倉庫配置淺析

最近遇到過不少這樣那樣的問題,曾經(jīng)做過maven的分享,但是發(fā)現(xiàn)當時部分內容還是太想當然了,下面經(jīng)過嘗試后簡單總結下:

首先幾個邏輯:

  • pom>啟用的profile>maven原有配置
  • mirror配置mirrorOf和id匹配優(yōu)先

簡單maven配置

一般大家的配置(略去無關私有倉庫配置)都是這樣的

<mirrors>
  <mirror>
      <id>nexus</id>
      <name>mvn.xxx.com</name>
      <mirrorOf>central</mirrorOf>
      <url>http://mvn.xxx.com/nexus/content/groups/t_repo_group/</url>         
  </mirror>
</mirrors>
  <profile>
      <id>dev</id>
      <repositories>       
      <repository>
        <id>nexus</id>
        <url>http://mvn.xxx.com/nexus/content/groups/t_repo_group/</url>
        <releases><enabled>true</enabled></releases>
                  <snapshots><enabled>true</enabled></snapshots>
      </repository>
                  
          <repository>
              <id>alibaba</id>
              <url>http://code.alibabatech.com/mvn/releases/</url>
              <releases>
                  <enabled>true</enabled>
              </releases>
              <snapshots>
                  <enabled>false</enabled>
              </snapshots>
          </repository>
         
      </repositories>
      
      <pluginRepositories>
          <pluginRepository>
        <id>nexus</id>
        <url>http://mvn.xxx.com/nexus/content/groups/t_repo_group/</url>
        <releases><enabled>true</enabled></releases>
                  <snapshots><enabled>true</enabled></snapshots>
      </pluginRepository>
      </pluginRepositories>
  </profile>  
<activeProfiles>
  <activeProfile>dev</activeProfile>
</activeProfiles>

mirrors

這個標簽重要的屬性包括id、mirrorOf。id用來唯一區(qū)分。mirrorOf用來關聯(lián)repository。
url用來表示私服地址。

mirrorOf常見大家配置成*、central、repo啥的。這里剛才提到了是用來關聯(lián)respository的,等提到下面<respository>標簽的時候在解釋。

profile

這個就簡單說下吧,就是算是個配置,可以配多個,具體哪個生效可以通過mvn命令指定,或者配置<activeProfiles>

repositories

這里面算是配置的重點

<repository>
      <id>alibaba</id>
      <url>http://code.alibabatech.com/mvn/releases/</url>
      <releases>
              <enabled>true</enabled>
      </releases>
      <snapshots>
               <enabled>false</enabled>
      </snapshots>
</repository>

幾個重要的配置,一目了然吧,id標識,url地址,是否從該倉庫下release,是否從該倉庫下快照版本。
這里就有人會懵逼了,這里怎么又配了個地址,跟mirrors里面的地址哪個生效呢?

好的,那咱們試試。先規(guī)定一下配置:

<mirrors>
    <mirror>
        <id>nexus</id>
        <name>mvn.ws.netease.com</name>
        <mirrorOf>central</mirrorOf>
        <url>http://mvn.xxx.com/nexus/content/groups/t_repo_group/</url>       
    </mirror>
  </mirrors>
  <repositories>       
        <repository>
          <id>nexus</id>
          <url>http://mvn.ccc.com/nexus/content/groups/t_repo_group/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
</repositories> 

把地址區(qū)分下,mirror里配成xxx,repository配成ccc
隨便找一個項目,設定一個不存在的依賴,mvn -U compile下:

可以發(fā)現(xiàn)去ccc找了。說明repository里的生效了。

那么mirror里的地址什么時候生效呢?其實剛才說了,mirror里的是靠mirrorOf中的內容和repository中id關聯(lián)的。比如我們把剛才配置改為

<mirrors>
    <mirror>
        <id>nexus</id>
        <name>mvn.ws.netease.com</name>
            <mirrorOf>central</mirrorOf>
        <url>http://mvn.xxx.com/nexus/content/groups/t_repo_group/</url>       
    </mirror>
  </mirrors>
  <repositories>       
        <repository>
          <id>central</id>
          <url>http://mvn.ccc.com/nexus/content/groups/t_repo_group/</url>
          <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
        </repository>
</repositories> 

把repository中的id改成central

這樣就行了。此外mirrorOf中可以配置通配符,例如*,表示任何repository都和這個關聯(lián)。

其實簡單來說就是如果repository的id能和mirrorOf關聯(lián)上,那么url以mirror的為準,否則以repository中自己的url為準。

其他還有一些點,repositories中可以配置多個repository,配置多個話,一個找不到會找下一個,比如我們在剛才基礎上加上阿里的配置

<repositories>       
        <repository>
          <id>nexus</id>
          <url>http://mvn.ccc.com/nexus/content/groups/t_repo_group/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
                <id>alibaba</id>
                <url>http://code.alibabatech.com/mvn/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository> 
</repositories>

在構建一次:

當配置多個時,會逐一進行下載嘗試。

總結

咱們在回顧下起初的配置,可以看到啟用的profile是dev,dev中的repository的id是nexus,跟mirrorOf沒有匹配,那么生效的配置就是repository中自己的url配置,所以這里完全可以省略掉mirror的配置。當然如果多個profile公用一個私服地址,也可以指定mirror地址,然后repository中的id指定成和mirrorOf相同,同時可以省略掉自己標簽中url。​

此外還有幾個點要說,pluginRepositories,配置信息基本和repository一致,不過這個地址是用來下maven的插件的,就是pom中這樣的配置

        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                            <filtering>true</filtering>
                            <targetPath>WEB-INF</targetPath>
                            <includes>
                                <include>**</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>

還有,pom也可以指定repository:

這樣配置會和settings.xml中生效的配置合并,并優(yōu)先從這個庫找,找不到繼續(xù)走settings.xml配置。

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關注腳本之家的更多內容!

相關文章

  • 淺談SpringBoot2.4 配置文件加載機制大變化

    淺談SpringBoot2.4 配置文件加載機制大變化

    這篇文章主要介紹了淺談SpringBoot2.4 配置文件加載機制大變化,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • 將java項目打包成exe可執(zhí)行文件的完整步驟

    將java項目打包成exe可執(zhí)行文件的完整步驟

    最近項目要求,需要將java項目生成exe文件,下面這篇文章主要給大家介紹了關于如何將java項目打包成exe可執(zhí)行文件的相關資料,文章通過圖文介紹的非常詳細,需要的朋友可以參考下
    2022-06-06
  • EasyCode整合mybatis-plus的配置詳解

    EasyCode整合mybatis-plus的配置詳解

    本文主要介紹了EasyCode整合mybatis-plus的配置詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-09-09
  • Spring Boot Gradle發(fā)布war到tomcat的方法示例

    Spring Boot Gradle發(fā)布war到tomcat的方法示例

    本篇文章主要介紹了Spring Boot Gradle發(fā)布war到tomcat的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • 關于eclipse中運行tomcat提示端口被占用的4種解決

    關于eclipse中運行tomcat提示端口被占用的4種解決

    這篇文章主要介紹了關于eclipse中運行tomcat提示端口被占用的4種解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Spring及Mybatis整合占位符解析失敗問題解決

    Spring及Mybatis整合占位符解析失敗問題解決

    這篇文章主要介紹了Spring及Mybatis整合占位符解析失敗問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-07-07
  • 詳解springmvc如何處理接受http請求

    詳解springmvc如何處理接受http請求

    這篇文章主要給大家介紹了springmvc如何處理接受http請求,文中通過代碼示例給大家講解的非常詳細,對大家的學習或工作有一定的幫助,需要的朋友可以參考下
    2024-02-02
  • Java仿Windows記事本源代碼分享

    Java仿Windows記事本源代碼分享

    這篇文章主要為大家詳細介紹了Java仿Windows記事本源代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • springboot學習筆記之 profile多環(huán)境配置切換的實現(xiàn)方式

    springboot學習筆記之 profile多環(huán)境配置切換的實現(xiàn)方式

    這篇文章主要介紹了springboot profile多環(huán)境配置切換的實現(xiàn)方式,本文給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-07-07
  • 多模塊項目引入SpringSecurity后一直報404的解決方案

    多模塊項目引入SpringSecurity后一直報404的解決方案

    這篇文章主要介紹了多模塊項目引入SpringSecurity后一直報404的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06

最新評論