Continuous delivery versioning in a Maven project
#devops #java #mavenYou can use a 'continuous delivery'-friendly version
value in your POM file, like this:
<version>${revision}</version>
Then, you should define a default version for non-CI builds in your properties:
<properties>
<revision>1.0.0-SNAPSHOT</revision>
</properties>
And finally, to bring it all together, you need to flatten your POM during the build process:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>${flatten-maven-plugin.version}</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>clean-flattened-files</id>
<goals>
<goal>clean</goal>
</goals>
<phase>clean</phase>
</execution>
<execution>
<id>generate-flattened-resources</id>
<goals>
<goal>flatten</goal>
</goals>
<phase>process-resources</phase>
</execution>
</executions>
</plugin>
This is what tells Maven to resolve the 'continuous delivery'-friendly version number before continuing.
At build time, you need to include the below in your Maven args:
-Drevision=1.2.3-whatever