I have a maven project which I do get the new project version from user with:
Current Version = 1.0.0
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>set</goal>
</goals>
</execution>
</executions>
</plugin>
Current Version = 2.0.0
and after that I called my own custom plugin, which runs set of calculations and appends an String to the version
Current Version = 2.0.0
<groupId>mygroup</groupId>
<artifactId>my artifact</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
Current Version = 2.0.0-AddedString
but when I run other plugins, for example:
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<executions>
<execution>
<id>end</id>
<goals>
<goal>echo</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<message>${project.version}</message>
</configuration>
</execution>
</executions>
which gives me the result of : "1.0.0" which should be "2.0.0-AddedString"
but why? and how to fix this? I need all plugins use the new version and work with that.
You need separate Maven runs for that.
If you run something like mvn versions:set -DnewVersion=2.0.0 my:plugin
, then my:plugin
will see the version as it was before starting the command, not the 2.0.0
that was set in between.
So when you have goals that change the POM, you need to call them in separate Maven runs, i.e. first mvn versions:set -DnewVersion=2.0.0
and then mvn my:plugin
.