[英]how to apply semantic versioning to the java maven project to automatically increment the version inside pom.xml
Can anyone please tell me how to apply the semver to the java maven project?谁能告诉我如何将 semver 应用于 java maven 项目? I tried many ways, but I didn't find any useful resources to automatically increase the version when I push the code to the branch.
我尝试了很多方法,但是我没有找到任何有用的资源来在我将代码推送到分支时自动增加版本。 I'm using Github action workflow to deploy the project into GitHub.
我正在使用 Github 操作工作流将项目部署到 GitHub 中。
Thank you.谢谢你。
After some reading, here is what I have found.经过一番阅读,这是我发现的。 Keep in mind, I have not tested any of these nor am I very knowledgeable with CI's and automation techniques.
请记住,我没有测试过任何这些,我对 CI 和自动化技术也不是很了解。
Potential Simple way: Maven Release Plugin潜在的简单方式: Maven 发布插件
With CI integration:使用 CI 集成:
My first approach is to use the command line but you have to configuration the following in your pom file before.我的第一种方法是使用命令行,但您必须先在 pom 文件中配置以下内容。 You can of course directly use the command line and put everything on the plain command without this setup but it's very inconvenient
您当然可以直接使用命令行并将所有内容放在普通命令上,无需此设置,但这非常不方便
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.9.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<executions>
<execution>
<id>major</id>
<goals>
<goal>set</goal>
</goals>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${parsedVersion.nextMajorVersion}.0.0-SNAPSHOT</newVersion>
</configuration>
</execution>
<execution>
<id>minor</id>
<goals>
<goal>set</goal>
</goals>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT</newVersion>
</configuration>
</execution>
<execution>
<id>patch</id>
<goals>
<goal>set</goal>
</goals>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}-SNAPSHOT</newVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
By using the above configuration you can change/update the version of your project like this:通过使用上述配置,您可以像这样更改/更新项目的版本:
mvn build-helper:parse-version versions:set@major
This will increment the major version and set minor and patch version to 0
.这将增加主要版本并将次要版本和补丁版本设置为
0
。
mvn build-helper:parse-version versions:set@minor
This will increment the minor version and set patch version to zero.这将增加次要版本并将补丁版本设置为零。
mvn build-helper:parse-version versions:set@patch
this will increment the patch version.这将增加补丁版本。 Afterwards you have to commit your changed back into your version control system (for example git).
之后,您必须将更改提交回您的版本控制系统(例如 git)。
I recommend to define this kind of setup into a parent pom and reuse it for multiple projects.我建议将这种设置定义为父 pom 并将其重用于多个项目。 A detail explanation why and how this works can be found here https://blog.soebes.de/blog/2021/04/05/maven-plugin-configuration/
可以在此处找到其工作原理和方式的详细说明https://blog.soebes.de/blog/2021/04/05/maven-plugin-configuration/
Using the maven-release-plugin is also an option.使用 maven-release-plugin 也是一种选择。 It will make also the tags in your version control.
它还将在您的版本控制中创建标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.