1、准备pom---distributionManagement发布管理
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.1.111:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>releases</id>
<url>http://192.168.1.111:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
2、添加SCM
<scm>
<url>项目git浏览器地址</url>
<connection>scm:git:项目git地址(http和ssh都支持)</connection>
<developerConnection>scm:git:项目git地址(http和ssh都支持)</developerConnection>
<tag>版本号</tag>
</scm>
3、设置setting.xml
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
4、确保distributionManagement中id与server中id一一对应
5、插件管理:
添加build节点
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<charset>UTF-8</charset>
<locale>zh_CN</locale>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<tagBase>${project.artifactId}-${project.version}</tagBase>
<!-- <releaseProfiles>release</releaseProfiles>-->
<goals>-f pom.xml deploy</goals>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
</plugin>
maven-source-plugin:源码打包
maven-javadoc-plugin:javadoc
maven-release-plugin release插件
6、常用命令:
mvn clean
mvn compile
mvn release:prepare -DautoVersionSubmodules=true -Darguments="-DskipTests" -DreleaseVersion=1.0 -Dtag=1.0 -DdevelopmentVersion=1.1-SNAPSHOP
mvn release:perform -DuseReleaseProfile=false -Darguments="-DskipTests"
7、常见问题:
(1)mvn release:prepare
做发布准备时,报错,javadoc
解决:
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
...
</properties>
(2)Cannot prepare the release because you have local modifications
解决:把本地代码全部提交到git