Adding git information to your Spring Actuator Info endpoint with Gradle


This is how you can add git related information in case you need that to keep track what functionality and code your development or test environments are using.


First you need to add the following to your Gradle file:

plugins {
   id "com.gorylenko.gradle-git-properties" version "1.4.21"

apply plugin: 'com.gorylenko.gradle-git-properties'

After this you should have a new Gradle task that will generate a file that your Actuator Info Endpoint can use. This file by default is generated into the build path resources folder. So run this command before building your jar or docker image etc.

gradle generateGitProperties


If you want to access the Info actutor enpoint to display that info from somewhere else you can do this:
InfoEndpoint infoEndpoint;

return new JSONObject(this.infoEndpoint.invoke()).toString();



Spring Boot Cache – Custom KeyGenerator

I created this kind of a bean to have trully unique keys for caching trough annotations @Cachable, @CachePut etc.

    public KeyGenerator keyGenerator() {
        return new KeyGenerator() {
            public Object generate(Object o, Method method, Object... objects) {
                // This will generate a unique key of the class name, the method name,
                // and all method parameters appended.
                StringBuilder sb = new StringBuilder();
                for (Object obj : objects) {
                return sb.toString();