Vivere
Vivere

Reputation: 2270

Maven overwrite version tag

In my project's POM file, there are some tags

<groupId>foo.bar</groupId>
<artifactId>foobar</artifactId>
<version>X</version>
<description>foo bar foo bar</description>

specified. I'm doing some builds using Jenkins and I want to overwrite that X value. How can I do that?

As an example, I'm more familiar with MSBuild and there I can do something like

msbuild.exe project.sln ...some options... /p:AssemblyVersion=X

Is that AssemblyVersion that I'm talking about. Is this possible with maven?

Besides that, is this even a good practice? At the moment, I have version 1.0-SNAPSHOT. Should I manually change that value? How to perform a release?

Upvotes: 0

Views: 871

Answers (1)

vijay v
vijay v

Reputation: 2076

To update version in pom files automatically from Jenkins, use -DnewVersion argument along with mvn command.
Example:

mvn versions:set -DnewVersion=someversion

During buildtime, if you'd like to update the buildnumber as your artifact version, then you can just pass that environment variable like -DnewVersion=${BUILD_NUMBER}.

Edit 1:
Credits to this SO thread updating-version-numbers-of-modules-in-a-multi-module-maven-project. It has a clear explanation.

Upvotes: 1

Related Questions