激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - Java Maven settings.xml中私有倉庫配置詳解

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

2022-02-16 14:26BJT Java教程

這篇文章主要介紹了詳解Maven settings.xml配置,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

 

Maven setting中私有倉庫配置淺析

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

首先幾個(gè)邏輯:

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

 

簡(jiǎn)單maven配置

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

<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

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

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

 

profile

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

 

repositories

這里面算是配置的重點(diǎn)

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

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

好的,那咱們?cè)囋?。先?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
隨便找一個(gè)項(xiàng)目,設(shè)定一個(gè)不存在的依賴,mvn -U compile下:

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

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

那么mirror里的地址什么時(shí)候生效呢?其實(shí)剛才說了,mirror里的是靠mirrorOf中的內(nèi)容和repository中id關(guān)聯(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

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

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

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

其他還有一些點(diǎn),repositories中可以配置多個(gè)repository,配置多個(gè)話,一個(gè)找不到會(huì)找下一個(gè),比如我們?cè)趧偛呕A(chǔ)上加上阿里的配置

<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>

在構(gòu)建一次:

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

當(dāng)配置多個(gè)時(shí),會(huì)逐一進(jìn)行下載嘗試。

 

總結(jié)

咱們?cè)诨仡櫹缕鸪醯呐渲?,可以看到啟用的profile是dev,dev中的repository的id是nexus,跟mirrorOf沒有匹配,那么生效的配置就是repository中自己的url配置,所以這里完全可以省略掉mirror的配置。當(dāng)然如果多個(gè)profile公用一個(gè)私服地址,也可以指定mirror地址,然后repository中的id指定成和mirrorOf相同,同時(shí)可以省略掉自己標(biāo)簽中url。?

此外還有幾個(gè)點(diǎn)要說,pluginRepositories,配置信息基本和repository一致,不過這個(gè)地址是用來下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:

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

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

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注服務(wù)器之家的更多內(nèi)容!

原文鏈接:https://www.jianshu.com/p/b734f075a85a

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 手机在线看片国产 | 一区小视频| 欧美老逼| 日韩欧美精品中文字幕 | 永久av在线免费观看 | 91精品国产91久久久久久 | 男男成人高潮片免费视频欧美 | 国产日韩精品欧美一区视频 | 国产小视频一区 | 午夜视频在线 | 久草视频在线资源 | 国产四区 | www.99热精品 | 国产一区二区三区在线免费 | 水多视频在线观看 | 国产女同疯狂激烈互摸 | 国产99久久久国产精品下药 | 国产91av视频 | 91看片成人 | 成人免费国产 | 欧美亚州| 少妇一级淫片免费放正片 | a级在线| 爱性久久久久久久 | 日韩欧美中文字幕视频 | 久色免费视频 | 特片网久久 | 日韩精品a在线观看 | 欧美日本亚洲视频 | 精品国产一区二区三区四区阿崩 | 911视频免费版 | 日韩激情在线视频 | 99精品热视频 | 男女无套免费视频 | 成年免费网站 | 久久精品视频首页 | 欧美日韩精品一区二区三区不卡 | 欧美第1页 | 亚洲精品成人久久 | 国产精品久久久久久久四虎电影 | 国产青草视频在线观看 |