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

Java項(xiàng)目打包發(fā)布到maven私倉(cāng)常見(jiàn)的幾種方式

 更新時(shí)間:2021年03月24日 09:09:04   作者:https://segmentfault.com/a/1190000039383875  
這篇文章主要介紹了項(xiàng)目打包發(fā)布到maven私倉(cāng)常見(jiàn)的幾種方式,幫助大家更好的理解和學(xué)習(xí)使用Java,感興趣的朋友可以了解下

前言

在早期沒(méi)有使用maven之前,我們引用一些公有jar或者api jar,我們可能會(huì)采用這樣的方式,通過(guò)手動(dòng)導(dǎo)入這些jar到項(xiàng)目的classpath路徑進(jìn)行引用。

有了maven后,我們公司內(nèi)部可能就會(huì)搭建maven私倉(cāng)比如nexus,然后把這些公有jar或者api jar上傳到nexus私倉(cāng),在pom.xml配置一下這些jar的坐標(biāo)就可以引用。

今天我們的話(huà)題就是來(lái)聊聊項(xiàng)目打包發(fā)布到maven私倉(cāng)常見(jiàn)的幾種方式

發(fā)布到maven私倉(cāng)的步驟

1.在maven的settings.xml中< servers >節(jié)點(diǎn)配置用戶(hù)名和密碼,形如下:

<servers>
 <server>
  <id>nexus-releases</id>
  <username>admin</username>
  <password>admin123</password>
 </server>
 <server>
  <id>nexus-snapshots</id>
  <username>admin</username>
  <password>admin123</password>
 </server>
 </servers>

注: 其中id可先看做是一個(gè)標(biāo)識(shí)。username和password為nexus私倉(cāng)的用戶(hù)名和密碼

2、指定發(fā)布到nexus私倉(cāng)的url并進(jìn)行發(fā)布

方式一:pom.xml文件添加distributionManagement節(jié)點(diǎn)

形如下:

 <distributionManagement>
   <!--正式版本-->
  <repository>
   <!-- 在settings.xml中<server>的id-->
   <id>nexus-releases</id>
   <url>http://192.168.0.11:8081/nexus/content/repositories/releases/</url>
  </repository>

   <!--快照版本-->
  <snapshotRepository>
    <id>nexus-snapshots</id>
    <url>http://192.168.0.11:8081/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
 </distributionManagement>

注:

  • 如果存在parent,只需在parent中的pom.xml中配置,沒(méi)有則在本項(xiàng)目的pom.xml配置即可
  • < repository >節(jié)點(diǎn)下的< id >對(duì)應(yīng)maven的配置文件settings.xml文件中的server的id,兩者必須保持一致
  • 上傳到私倉(cāng)的是正式版本還是快照版本,取決于pom.xml文件version中是SNAPSHOT還是RELEASE。比如你項(xiàng)目中配置如下
<groupId>com.example</groupId>
 <artifactId>demo</artifactId>
 <version>0.0.1-SNAPSHOT</version>

則上傳到私倉(cāng)的就是快照版本

最后執(zhí)行maven的deploy命令進(jìn)行發(fā)布

方式二:在maven的settings.xml中< profiles >節(jié)點(diǎn)配置< properties >,并在< properties >指定<altSnapshotDeploymentRepository > 和< altReleaseDeploymentRepository >

形如下:

<profiles>
  <profile>
  <id>nexus</id>
  <properties>
   <altSnapshotDeploymentRepository>
    nexus-snapshots::default::http://192.168.0.11:8081/repository/maven-snapshots/
   </altSnapshotDeploymentRepository>
   <altReleaseDeploymentRepository>
   nexus-releases::default::http://192.168.0.11:8081/repository/maven-releases/
   </altReleaseDeploymentRepository>
  </properties>
 </profile>
 </profiles>
 <activeProfiles>
 <activeProfile>nexus</activeProfile>
 </activeProfiles>

注:

  1. nexus-snapshots和 nexus-releases要和maven的配置文件settings.xml文件中的server的id,兩者必須保持一致
  2. 屬性altSnapshotDeploymentRepository和altReleaseDeploymentRepository是隨maven-release-plugin 2.8版一起引入的。低于2.8版本,執(zhí)行mvn deploy時(shí),則會(huì)報(bào)如下錯(cuò)誤
Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

解決方案就是在發(fā)布的項(xiàng)目中指定一下2.8版本以上的插件,形如下

<build>
  <plugins>
   <plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
   </plugin>
  </plugins>
 </build>

最后再執(zhí)行maven的deploy命令進(jìn)行發(fā)布

方式三:通過(guò)mvn deploy指定參數(shù)

方法一:通過(guò)-D參數(shù)指定altSnapshotDeploymentRepository和altReleaseDeploymentRepository
形如下

mvn deploy -DskipTests -DaltSnapshotDeploymentRepository=nexus-snapshots::default::https://YOUR_NEXUS_URL/snapshots
-DaltReleaseDeploymentRepository=nexus-releases::default::https://YOUR_NEXUS_URL/releases

同理上述命令要執(zhí)行成功,得確保deploy插件是基于2.8版本以上

方法二:通過(guò)-D指定要發(fā)布的jar的相關(guān)信息以及私倉(cāng)地址,私倉(cāng)id,私倉(cāng)id要和settings.xml文件中的server的id保持一致
形如下

mvn deploy:deploy-file -DskipTests -Dfile=jar包文件地址,絕對(duì)路徑 -DgroupId=組名 -DartifactId=項(xiàng)目名稱(chēng) -Dversion=版本號(hào) -Dpackaging=jar -DrepositoryId=私庫(kù)id(和setting.xml文件中的server的id保持一致) -Durl=私倉(cāng)地址

方式四:通過(guò)nexus的可視化界面進(jìn)行上傳jar發(fā)布

這幾種發(fā)布方式的選擇

方式一,通過(guò)distributionManagement這種方式發(fā)布,可能是大多數(shù)人的選擇。但如果要發(fā)布的項(xiàng)目很多,我們就可以考慮使用方式二,通過(guò)在全局的settings文件配置altSnapshotDeploymentRepository 和altReleaseDeploymentRepository進(jìn)行發(fā)布,只需配置一次,所有項(xiàng)目就都可以發(fā)布,無(wú)需在多個(gè)項(xiàng)目pom指定

方式一和方式二比較適合公司自己內(nèi)部開(kāi)發(fā)項(xiàng)目,對(duì)于一些第三方提供的jar,推薦使用mvn deploy -DrepositoryId=私庫(kù)id(和settings.xml文件中的server的id保持一致) -Durl=私倉(cāng)地址的方式或者直接使用nexus可視化界面上傳的方式

以上就是項(xiàng)目打包發(fā)布到maven私倉(cāng)常見(jiàn)的幾種方式的詳細(xì)內(nèi)容,更多關(guān)于項(xiàng)目打包發(fā)布到maven的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

顺平县| 新巴尔虎左旗| 古丈县| 吉水县| 永宁县| 余庆县| 泊头市| 衡水市| 社会| 射阳县| 民乐县| 汤原县| 衡水市| 阿克陶县| 永胜县| 万源市| 上栗县| 江华| 遵义市| 金华市| 论坛| 正安县| 乾安县| 古蔺县| 张家口市| 屏东县| 贵德县| 吴川市| 闻喜县| 武宁县| 汶川县| 类乌齐县| 莲花县| 中方县| 连州市| 松滋市| 津南区| 山阴县| 辽阳县| 成安县| 乌兰察布市|