1.scm配置
<scm>
<!--只读权限的git地址,可以和developerConnection一样,如果权限没有细分的话-->
<connection>scm:git:http://git.i-tuan.cn/tmall/common.git</connection>
<!--具有写权限的git地址-->
<developerConnection>scm:git:http://git.i-tuan.cn/tmall/common.git</developerConnection>
<!--项目查看地址-->
<url>http://git.i-tuan.cn/tmall/common</url>
</scm>
2.插件配置
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<!--
可选属性为:
project.groupId 对应于项目的groupId。
project.artifactId 对应于项目的artifactId。
project.version 对应于项目的发行版本。
-->
<tagNameFormat>v{project.version}</tagNameFormat>
<!--因为是聚合工程,设置这个参数免去为每个子模块设置版本号的动作,统一使用聚合模块的版本号-->
<autoVersionSubmodules>true</autoVersionSubmodules>
<!--git 账号密码-->
<username>xxx</username>
<password>xxxxx</password>
<!--禁用超级pom中的profile文件-->
<useReleaseProfile>false</useReleaseProfile>
<!--使用自定的profile文件-->
<releaseProfiles>release-profile-consumer</releaseProfiles>
</configuration>
</plugin>
3.自定义profile
<profile>
<id>release-profile-consumer</id>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
自定以profile可以不用,因为在super pom中定义了一个profile当执行release:perform时被激活,且会执行javadoc插件。但是项目中的doc没有根据标准来,因此报错。无法继续执行,所有才有这个自定义的文档。
4.release的操作流程
4.1第一步release:prepare
这条命令主要是做打包前的准备。
输入对应的release需要打包的版本等信息,如果不输入有默认的内容 将需要记录和准备的内容缓存到pom.xml目录下的release.properties文件中 在本地和远程库的GIT中打上对应版本的tag在准备过程中还会run 单元测试等phase,如果没有异常的话可以继续最后一步。如果git还没有commit或单元测试失败会导致prepare失败,这时候你就需要到下面一个命令了。
4.2后悔药release:rollback
如果在准备阶段发生错误,或者需要修改某些地方的话。就需要到这个命令了,这个命令执行以后会做以下这些事
删除线上git库tag,但是本地库tag没有被删除,需要手动使用git tag -d XXX进行删除。如果不将本地库中的tag删除将会导致prepare失败。 删除之前缓存在pom.xml统一目录下的配置4.3最后一步release:perform
如果确认无误了以后,就可以执行perform命令了。这个命令干了以下这些事:
验证代码合法性 将你之前的1.0-SNAPSHOT改为1.1-SNAPSHOT 将1.0版本deploy至scm配置的nexus release库中 将代码source。jar版本 javacode。jar打包上传至nexus库恭喜,你已经把你的1.0-SNAPSHOT成功的打包成1.0的release版本了。同时你会发现你的pom.xml文件会自动的变成1.1-SNAPSHOT版本。虽然这一系列操作都可以通过手动完成。但是有这个工具的存在,免去了很多步骤。也规范了流程,何乐而不为呢。