Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: change version properties in pom.xml

Tags:

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

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> 

How can this be done?

like image 345
user2004266 Avatar asked Jan 23 '13 15:01

user2004266


People also ask

How do I change the release in POM xml?

mvn scm:checkin -Dincludes=pom. xml -Dmessage="Setting version, preping for release." 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.

How use properties file in POM xml?

properties file in the maven project folder src/main/resources`. In pom. xml, add resources inside the building element and set filtering=true. filtering enables replacement variables from a project, or system to the resource files.

What is version in Maven POM xml?

version. It is the sub element of project. It specifies the version of the artifact under given group. File: pom.xml.


1 Answers

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" 

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." 

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.

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.

like image 194
Anew Avatar answered Sep 18 '22 18:09

Anew