昨天,根据领导的要求,需要对部门的产品进行新版本的发布,问了之前的人,需要做的就是在改pom文件为新版本号,提交git代码,在git中建基线,再次修改版本号,再次提交git。
同时给了之前打基线的一个文档,其中提到的是使用maven的release插件自动执行。中间折腾了好久,又是maven的用户名密码不对,导致没有权限,亦或者是我本机安装的git提交有问题。总之折腾了好久,早上在同事的帮助下,终于成功了,记录下来。
pom文件中配置builg的地址
<description>bbb 3rd project management</description>
<scm>
<connection>scm:git:ssh://git@x.x.x.x/aaa/bbb</connection>
<url>scm:git:ssh://git@x.x.x.x/aaa/bbb</url>
<developerConnection>scm:git:ssh://git@x.x.x.x/aaa/bbb</developerConnection>
<tag>HEAD</tag>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
maven的setting.xml文件中设置release和snapshot的服务器信息。其中,用户名、密码、id和url需要根据真实的值进行配置:
<server>
<id>repository-snapshots</id>
<username>deployment1111</username>
<password>deployment1111</password>
</server>
<server>
<id>repository-releases</id>
<username>deployment1111</username>
<password>deployment1111</password>
</server>
<profile>
<id>repository-releases</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>repository-snapshots</id>
<name>Repository for SNOPSHOT</name>
<url>http://XX.XX.XX.XX:8081/nexus/content/repositories/repository-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>repository-snapshots</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>repository-snapshots</id>
<name>Repository for SNOPSHOT</name>
<url>http://XX.XX.XX.XX:8081/nexus/content/repositories/repository-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
确保代码已提交到git,且与git保持一致后,在git命令行(或者以管理员身份启动windows自带的cmd)输入:
mvn release:prepare
经过一系列版本号及新版本号的确认,之后就是一长串的日志输出信息,主要工作为改pom文件、提交git、打标签、build、提交maven仓库、改pom文件等等的输出信息。(理论上是这些内容)。可以确认一下git上的标签是否打成功,pom文件是否提交成功,pom文件是否改为新的snapshot的值。
再次将更改后的新的快照pom文件提交git。
执行下面代码,删除release的过程文件,会再次打包,上传maven。
mvn release:perform -Darguments="-Dmaven.javadoc.skip=true"
执行后,我的maven仓库没有打包发布release和新版本的快照文件,用的是部门的jenksin工具,让它打包发布到maven仓库的。成功。