上傳源碼
項目中采用了分模塊的方式構建,直接將maven-source-plugin寫到父pom中,嘗試了很多次發現源碼一直不能上傳到私服中,糾結了很長時間才發現原來多模塊項目和普通一個項目的配置是有區別的,需要在每個需要上傳源碼的子模塊中都配置maven-source-plugin才可以上傳,於是乎有了一下的代碼
1,非多模塊項目
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins>
2,多模塊項目
在父pom中增加
<pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement>
子項目中增加
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> </plugin> </plugins> </build>
然后使用:mvn deploy 既可將源碼上傳到私服中
打包問題
封裝過公共組件的同志們都知道,工具組件需要不斷的維護升級,還好現在有maven來幫助我們管理各個版本的jar包,但是如何正確的使用maven來讓團隊使用我們jar呢,這就是我們接下來介紹的。
首先我們開發的版本都是 SNAPSHOT ,但是當被項目組使用的時候需要發布RELEASE版本來使用,這樣不至於我們更改的代碼影響團隊的使用。因此在deploy項目的時候我們可以分為三部來操作
mvn versions:set -DnewVersion=1.0.0.RELEASE
mvn deploy
mvn versions:set -DnewVersion=0.0.1-SNAPSHOT
第一步:我們設置當前項目的版本號為 1.0.0Release,這是maven會自動將多模塊中所有模塊的版本號都更改為當前我們設置的
第二步:繼續使用deploy上傳代碼
第三步:我們要繼續開發自己的功能,所以需要將項目中的版本號更改為SNAPSHOT
上面的1.0.0 和 0.0.1 需要根據項目來定,沒有固定的要求
pom中配置配置Nexus
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://x.x.x.x:port/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://x.x.x.x:port/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>