參考:https://www.cnblogs.com/chenhao0302/p/7793980.html
使用deploy命令部署jar到私服倉庫nexus
一 配置settings.xml(前提在nexus中創建好賬號密碼)
因爲nexus是需要登陸操作,這裏配置的是具有發佈權限的賬號,其中id要與pom文件中的id一致。
在settings.xml的<servers>裏配置:
<servers>
<server>
<id>nexus-releases</id>
<username>nexus-releases</username>
<password>123456</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>nexus-snapshots</username>
<password>123456</password>
</server>
</servers>
二、配置項目的pom.xml文件
其中id要與settings.xm文件中的id一致。
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://xxxx:8081/repository/maven-public/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://xxxx:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
如果在<build>標籤裏添加以下配置,將在發佈時將XXX-source.jar的源碼同時部署到倉庫
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
三、
運行 mvn deploy -DskipTests將項目部署到私服,部署並跳過測試
其它:
四、批量修改版本號
方式一: 在根module執行 mvn- versions:set -DnewVersion=XXX
方式二:更新了根module的版本號後執行 mvn -N versions:update-child-modules
五、用cmd執行(win10的powershell可能會執行失敗)
// 該方式是手動發佈jar到倉庫,不會發布source-jar
mvn deploy:deploy-file -DgroupId=net.xx.hello -DartifactId=xx-hello-Dversion=1.0.2-SNAPSHOT -Dpackaging=jar -Dfile=my-config-spring-1.0.2-SNAPSHOT.jar -DrepositoryId=Snapshots -Durl=http://repos.XXX.com:6060/nexus/content/repositories/snapshots/
其中:
-DgroupId -DartifactId -Dversion 是包在maven倉庫的座標地址,
-Dpackaging 指名包的類型 pom、jar、other
-Dfile 指明包的名字,可以是絕對路徑,也可以是相對路徑
-DrepositoryId 指明需上傳到目標倉庫的ID號
-Durl 指名需要上傳到目標倉庫的URL地址
六、注意事項
發佈子module的時候,父pom要同步發佈