If you found the contents in this blog useful, then please make a donation to keep this blog running. You can make donations via Skrill with email address

Tuesday, January 30, 2018

Git Commit Information in Spring MVC

At time there is a need for developers the need to know which Git Commit from which Git Branch was used to build a release so that they can keep track of the versions.
Spring Boot Actuator is tailor made for this if you are working on Spring Boot but if you are like me and not using Spring Boot for a specific project but only using Spring MVC then this guide will be helpful for you.
First of all you need to add the spring-boot-actuator
And then instead of relying on Spring Boot Autoconfiguration, in your Java Annotation configuration you can do the following;
And in order to generate the file you can use the Maven git-commit-id plugin and use it as below;
                 <name>validating project version</name>  
And when packaging you can use the following command
$ mvn clean package git-commit-id:revision 
Now when you access http://://info endpoint you will see the git commit id, branch name, commit time etc. and you can customize the pom.xml git-commit-id plugin configuration to have more information.