In maven it is very easy to set properties in a pom with the following syntax:
...
4.06.17.6
Ihor Kaharlichenko's answer is basically correct except that it copies an error from the Codehaus documentation. There should be no '\' between the '$' and the '{'. The mojo works without it and doesn't work with it. Truly, with a basic understanding of regex and Maven, I couldn't see what the backslash was supposed to do and indeed it's wrong.
Stephen Connolly's answer correctly omits the backslash. Be careful.
This error has proliferated throughout SO and with Codehaus out of business will probably never get fixed.
Mojo's Build-Helper Maven Plugin can help you out here.
There are a number of goals that can be used to help transform properties.
There is
build-helper:regex-property
build-helper:parse-version
build-helper:released-version
Probably regex-property is the one you want, but if your version numbers conform to the "standards" the other two might save you.
To use the regex-property goal you would do something like
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>tag.version</name>
<value>${project.version}</value>
<regex>^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.(-SNAPSHOT)?$</regex>
<replacement>V$1_$2_$3_P$4</replacement>
<failIfNoMatch>true</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Note: my regex might be slightly off so you should test the above.
Note: The property value will only be available for executions after the phase that this execution is bound to. The default phase that it is bound to is validate
but if you are on a different lifecycle (e.g. the site lifecycle) the value will not be available.
You can use maven build-helper plugin, in particular its regex-property mojo. Take a look at usage examples (scroll to Set a property by applying a regex replacement to a value section).
Basically you want something like that in your pom to get myVersionTag
property inferred from myValue
:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>myVersionTag</name>
<value>$\{myValue}</value>
<regex>(\d+)\.(\d+)\.(\d+)\.(\d+)</regex>
<replacement>V_$1_$2_$3_P$4</replacement>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>