Sunday, March 18, 2018

Application versioning with Git and Gradle

Please follow Rest API Server to see the big picture and GitHub repo details.

Application versioning in Git is tricky compared to subversion. Subversion commits are in the increasing order of number so it's easy to put them as part of the application version. Being numbers they are easy to comprehend. However, Git commit id's are hash which would frighten any faint-hearted. A typical git commit id may look like


Git provides tag functionality which can be used to something similar with respect to subversion. For the same, tag your branch with '-a' option. This creates an annotated tag.

git tag -a v0.1 -m "0.1 version"

Now doing a git tag command will show all the tags

git tag

Now do a describe

git describe

If you do any commit over this, the describe will increment the version and append last letters of commit id

git describe

Integrating into Gradle

To integrate into Gradle, one way is to add an implementation version in MANIFEST.MF file. This will allow the jar or bootJar task to use the version in creating the artifacts. (In Spring boot environment, I am seeing that jar task is not picked up. Not sure if that is intended or a bug. In this example, that's why you will see the version handling as part of bootJar task.)

bootJar {
    version= 'git describe'.execute().text.trim()
    manifest {

The application jar, in this case, will be generated with rms-<version>.jar. Also, the details are available in MANIFEST.MF file which can be accessed programmatically. Also for this, you will have to use the build task. bootRun task does not generate MANIFEST.MF file.

No comments:

Post a Comment