versions:set doesn't set version if non-direct properties are used in version element #916
Description
Maven supports 5 property classes in pom.xml files:
env.X
- environment variablesproject.x
- any project properties from the pom.xmlsettings.x
- properties from settings.xml- Java Systems Properties, e.g.
java.home
x
- properties from<properties>
section of the pom.xml
If any of the 1-4 property classes is used in version
element (even transitively) the resolution of the current version will fail, and no new version will be set.
E.g. parent pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.app</groupId>
<artifactId>my-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
</project>
child pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example.app</groupId>
<artifactId>my-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.example.app</groupId>
<artifactId>my-app</artifactId>
<version>${project.parent.version}</version>
</project>
Attempt to set version:
$ mvn versions:set -DnewVersion=1.1.1
(...)
[INFO] Building my-app 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.14.2:set (default-cli) @ my-app ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: C:\Work\projects\3rd_party\tst
[INFO] Processing change of com.example.app:my-app:1.0.0 -> 1.1.1
expression: project.parent.version no value
This caught us off guard - we use versions:set to override the version only for our 'dev' builds which are rather seldom run.
Workaround
$ mvn versions:set -DnewVersion=1.1.1 -DoldVersion='*'
(...)
[INFO] Building my-app 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.14.2:set (default-cli) @ my-app ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: C:\Work\projects\3rd_party\tst
[INFO] Processing change of com.example.app:my-app:* -> 1.1.1
expression: project.parent.version no value
[INFO] Processing com.example.app:my-app
[INFO] Updating project com.example.app:my-app
[INFO] from version to 1.1.1
I know this might be a corner case, and not really an issue, since it is encouraged that the version element is constant and not an expression. Furthermore I couldn't come up with other probable use cases.
Having said that, I think that because some property interpolation is already handled by the plugin, one might expect that all property classes may be used, and be surprised by this behavior.
Please consider whether it's worth handling.
Activity