Reputation: 893
Is there any config / plugin / setting that i can configure so that whenever i make a feature, the version tag updates <version>\*.\*.1 </version>
to <version>\*.\*.2 </version>
(for an example)?
And for a release it updates <version>\*.1.\* </version>
to <version>\*.2.\* </version>
?
Upvotes: 2
Views: 2592
Reputation: 3295
To start with the Git revision, in Maven, use the Build Number Maven Plugin:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>true</doUpdate>
</configuration>
</plugin>
</plugins>
This plugin uses the SCM element from the POM that the plugin runs from. After that plugin runs, you will have a build variable called ${buildNumber}
. Use that with variable interpolation via the Maven Resources Plugin to filter a Java .properties
file on your classpath:
Other variables from the build are also available, such as the version of the project. So your final property will look something like the following (adjust for personal taste):
build.number = ${buildNumber}-${project.version}
This can appear in any properties file, but be sure that there are no other properties that will be adversely affected by the filtering going on in the file! So you may want to do this on an additional file...
At that point, you can load the Git revision as a regular property using the key build.number
in your Java code.
Lastly, note that you can create a pretty nice setup with this by including the element in a top level POM, inheriting the declaration of the plugin into every subproject. This works well because even if you don't use the variable that is created by the plugin, it's existence does not affect anything.
EDIT: I see after answering that you want this revision in the version element of the POM, not the Java code, apologies. I would argue that you do not want to do this since it will very positively mess with the release plugin and could mess with repositories that have a very specific grammar related to version ordering and whether they are snapshots or release artifacts.
Upvotes: 1