Maven:更改pom.xml中的版本属性 [英] Maven: change version properties in pom.xml

查看:1143
本文介绍了Maven:更改pom.xml中的版本属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven pom.xml,我用Jenkins构建项目并发布项目部署.

I have a Maven pom.xml, I build project and release project deploy with Jenkins.

但是在构建发行版本"之前和之后,我们需要在

But before and after build "release version" we need set my version in

例如: 我在pom.xml中

For example: I have in pom.xml

<properties>
   <version-own>0.0.21-SNAPSHOT</version-own>
</properties>

发布之前,我需要这样设置

before release I need set like this

<properties>
   <version-own>0.0.25</version-own>
</properties>

发布后,我需要这样设置

after release I need set like this

<properties>
   <version-own>0.0.27-SNAPSHOT</version-own>
</properties>

这怎么办?

推荐答案

如果您不必使用自己的version属性,请考虑以下将对您的<project><version>0.0.21-SNAPSHOT</version></project>元素执行的操作:

If you don't have to use your own version property, consider the following that will operate on your <project><version>0.0.21-SNAPSHOT</version></project> element:

mvn versions:set versions:commit -DnewVersion="0.0.25"

这将修改您的pom并根据您的喜好调整版本.您可能希望将此更改提交到源代码控制存储库,为此,scm插件的scm:checkin目标工作正常(假设您希望此操作自动化):

That will modify your pom and adjust the version to your liking. You'll likely want to commit this change to your source code control repository, for this the scm plugin's scm:checkin goal works just fine (assuming you want this to be automated):

mvn scm:checkin -Dincludes=pom.xml -Dmessage="Setting version, preping for release."

然后您可以执行发布(我建议 maven-release-plugin ),之后您可以设置新版本并按上述要求进行提交.

Then you can perform your release (I recommend the maven-release-plugin), after which you can set your new version and commit it as above.

版本插件是您的朋友.编写上述脚本可能会涉及一些参数化的构建,或者最好是jenkins的groovy插件,该插件可让您获取特定于Maven的构建变量.

The versions plugin is your friend. Scripting the above would likely involve some parameterized build, or preferably the groovy plugin for jenkins which allows you to get the maven-specific build variables.

这篇关于Maven:更改pom.xml中的版本属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆