How to get a command-line property to overwrite a maven property
I have a pom file in which version numbers of some dependencies rely on the project version property specified in the settings of the pom file. Can I overwrite this via the command-line? If so, how?
Here's the long story:
We are currently transitioning our projects to maven, but we're not all the way there yet. There are multiple modules that are still not built with maven and are therefore dependencies in our project (they are built into jars through ant). Upon release, we want all of these jars to be built and contain the same version number as the parent project. For a release, two steps are performed (until we can get everything using maven)
- The jars are built in ant with the correct release version (12.12.4.0).
- The maven release plugin is used to deploy the project to our artifact repository.
In the second step command-line arguments are used to specify the release:
mvn release:prepare -DreleaseVersion=12.12.4.0 -DdevelopmentVersion=12.12.4.1-SNAPSHOT -Dtag=iv-12.12.4.0
I would like the pom file to be updated with the version specified. However, when this command is run, the version within the pom file (12.12.4.0-SNAPSHOT) is still being used. This fails the "checking dependencies and plugins for snapshots" step and I am required to resolve my jars that still have the 12.12.4.0-SNAPSHOT version used from the maven version property.
This led me to the original question of how I can override this so that the version resolves to that specified on the command line. Additional questions that could get me past this is: How to allow the maven release plugin to update the pom file before this check? How to skip the snapshot check (not desirable)
I could create a property within the pom file that I can overwrite, but then I'd have to maintain the version number in two places within the pom file.
Thoughts?
Solution 1:
Put parameters directly to pom from command line for example:
mvn clean install -Dtestng.version=6.3.1
Example:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<name>test</name>
<properties>
<testng.version>6.4</testng.version>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
If you run it normally testng version 6.4 will be used. But if you run it like: mvn clean install -Dtestng.version=6.3.1
testng version 6.3.1 will be used.
See Setting Maven params in Jenkins