Reputation: 241
I've got a Jenkins/maven build where we need to be able to produce release artifacts with arbitrary version numbers. The version number is passed in as a parameter to the build job. I'm using versions:set
to update the version from what is in the pom.xml to the $VERSION parameter. When the build is run, it appears that maven does in fact update the version in the working copy of the pom.xml, however it builds the artifact with the old version number.
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>someservice</name>
<groupId>com.domain.group</groupId>
<artifactId>someservice</artifactId>
<version>1.0.0-SNAPSHOT</version>
Invoke top-level maven targets in Jenkins job:
-V
-B
-e
-U
clean
versions:set
-DnewVersion=${VERSION}
package
deploy
-Dmaven.test.skip=true
My build output looks something like this (with a $VERSION of 0.1.2)
[INFO] ------------------------------------------------------------------------
[INFO] Building someservice 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:set (default-cli) @ someservice ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /svn/group/someservice/trunk
[INFO] Processing change of com.domain.group:someservice:1.0.0-SNAPSHOT -> 0.1.2
[INFO] Processing com.domain.group:someservice
[INFO] Updating project com.domain.group:someservice
[INFO] from version 1.0.0-SNAPSHOT to 0.1.2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.147s
[INFO] Finished at: Wed May 20 11:40:46 PDT 2015
[INFO] Final Memory: 10M/180M
[INFO] ------------------------------------------------------------------------
I've noticed that while the initial run will build with the old version, if the working dir is not reverted, subsequent runs will correctly build with the new version in the updated pom.xml. How can I get the pom file updated with the new version before the artifacts are built?
Constraints:
mvn versions:set -DnewVersion=0.1.2
) and the behavior is the sameUpvotes: 2
Views: 2448
Reputation: 6204
What you want to achieve is not possible with current maven versions, as stated in the Usage section of the versions-maven-plugin:
Maven 2.0, 2.1, 2.2 and 3.0 do not currently support re-reading modifications of the pom.xml within one invocation of Maven.
How about adding another build step here?
Upvotes: 1