需求描述
在项目迭代过程中,需要为不同的版本号打上 Tag,对于发行的稳定版本则需要上传到指定的仓库。手动操作则过于繁琐,且无法统一 Tag 的样式,因此需要一款实现自动的可配置的发行工具。
解决方案
使用 maven-release-plugin 插件,其提供了自动追赠版本号、自动切换 snapshots 和 releases 版本、以及自动打 Tag 与版本发行等功能。
配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
   | 
  <scm>     <connection>scm:git:url</connection>     <developerConnection>scm:git:url</developerConnection>     <tag>HEAD</tag> </scm>
  <plugin>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-release-plugin</artifactId>      <version>3.0.0-M1</version>      <configuration>          <username>scm 用户名</username>                    <password>scm 密码</password>          <scmCommentPrefix>[提交信息的前缀]</scmCommentPrefix>        	           <autoVersionSubmodules>true</autoVersionSubmodules>                    <tagNameFormat>v@{project.version}</tagNameFormat>                    <arguments>-DskipTests -DuseReleaseProfile=false</arguments>                    <tagBase>https://gitee.com/{用户名}/{项目名}/tags</tagBase>      </configuration>  </plugin>
 
 
  <distributionManagement>     <repository>         <id>rdc-releases</id>         <url>https://packages.aliyun.com/maven/repository/2046382-release-Kot3ui/</url>     </repository>     <snapshotRepository>         <id>rdc-snapshots</id>         <url>https://packages.aliyun.com/maven/repository/2046382-snapshot-sZVDXF/</url>     </snapshotRepository> </distributionManagement>
 
   <servers> 		<server>       	 				<id>rdc-releases</id> 				<username>用户名</username> 		    <password>密码</password>     </server>     <server>         <id>rdc-snapshots</id>         <username>用户名</username>         <password>密码</password>     </server>  </servers>
 
  | 
 
正式发行一定要配置 distributionManagement 且要注意授权信息(账号、密码)是否填写且正确,否则授权无法通过产生 401 异常。
使用
1 2 3 4 5 6
   |  mvn release:prepare
  mvn release:perform
  mvn release:rollback
 
  | 
 
在 idea 可以通过可视化插件使用,需要注意的时,正式发行前一定要先进行预备发行。且每次打 Tag 时必须要求 git 是最新提交,正式发行使用的是上次 Tag(历史提交) 中的 pom,因此每次修改需要先提交到 git。

注意事项
- 提交时出现 
remote: Invalid username or password,确保自己的登录信息没有错,则尝试使用 repo token 来替换密码; 
- 发布 prepare 之后,会产生各个模块的 pom 备份文件,最好在提交之前加入 .gitignore;