Are you looking for an easy way to handle versioning of your maven projects? Use the jgitver maven plugin! In this post we will setup the plugin and show some of the main features.
For a complete overview of the plugin and its workings please visit the jgitver github here.
As an example we will use a maven project from this previous post on how to create your own maven plugin. The complete code for this post can be found on github here.
The plugin is easiest in combination with the maven wrapper. With this wrapper you can run maven commands without having this installed on your computer or use a different version. Some project archetypes or cli generators already add this wrapper. You can also use the following command.
mvn -N io.takari:maven:wrapper
You can now run maven commands with the added executable.
./mvnw clean install
If we take a look at the output we see that we build version
0.0.0-SNAPSHOT, as defined in the pom.
.mvn directory holds the configuration of the maven wrapper. This is the place we add the jgitver plugin by adding an extensions file
extensions.xml with the following content.
A new build now results in the following version.
It’s a combination of the version, the branch that I’m on and SNAPSHOT. Cool! Now we would like to release a stable version 1.0.0. This would be a build from the master branch so let’s merge.
After merging we set a tag for this stable version.
git tag 1.0.0 -m "Stable version 1.0.0"
Another build wil use this tag to craft the maven version. Note that the reference to the branch wil be omitted for the master branch.
Hopefully you found this to be a nice introduction to the jgitver plugin and hopefully it will help you manage your versions. Happy versioning!