我遇到了同样的问题,我想在不运行多个命令或手动插入版本的情况下解决它。
这是我对 y (或次要)增量的解决方案:
我在初始化阶段运行了一个 Groovy 脚本。该脚本创建release.properties。将此添加到pom.xml中的project/build/plugins部分:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.6</version>
</dependency>
</dependencies>
<executions>
<!-- Force maven-release-plugin to increase MINOR, not PATCH, and create tag as vX.Y.Z -->
<execution>
<id>release-parameters</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>
<![CDATA[
final String SNAPSHOT = '-SNAPSHOT'
Properties releaseProps = new Properties()
File releasePropsFile = new File('release.properties')
String releaseVersion = '${project.version}'.replace('-SNAPSHOT', '')
String[] vNumbers = releaseVersion.split('\\.')
String snapshotVersion = vNumbers[0] + '.' + (Integer.parseInt(vNumbers[1]) + 1) + '.' + '0' + SNAPSHOT
releaseProps.setProperty('scm.tag', 'v' + releaseVersion)
releaseProps.setProperty('project.rel.${project.groupId}:${project.artifactId}', releaseVersion)
releaseProps.setProperty('project.dev.${project.groupId}:${project.artifactId}', snapshotVersion)
releaseProps.store(releasePropsFile.newWriter(), null)
]]>
</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>
此脚本还会更改SCM中vX.YZ的标签名称。在release:prepare阶段不执行初始化阶段。要解决此问题,您可以在发布之前运行“mvn install”,或将发布命令更改为:
mvn --batch-mode initialize clean release:prepare release:perform
关于release.properties:https://maven.apache.org/maven-release/maven-release-plugin/examples/non-interactive-release.html