Showing git properties with Actuator¶
Not a simple solution¶
Unluckily there is no way to do this both with Maven and Gradle at the same time. Some minor changes in dependencies and configuration must be done in each case. The same code won’t work with Maven and Gradle.
With Gradle¶
The way of doing this when using Gradle is to use the gradle-git-properties plugin.
First of all, add the dependency. Note that the Gradle plugin portal repository has to be added also.
buildscript {
...
repositories {
...
gradlePluginPortal() // Repo of community Gradle plugins.
}
dependencies {
...
classpath('gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:2.0.0')
}
}
Following the buildscript block comes the plugin configuration. Just add the fields you want, following the same name they have in the git.properties file. This file is generated by the plugin at build time.
// git data to show.
// Comes from generated git.properties file.
gitProperties {
keys = [
'git.branch',
'git.dirty',
'git.commit.id',
'git.commit.message.full',
'git.commit.user.name',
'git.commit.user.email',
'git.remote.origin.url',
'git.build.host',
'git.build.version'
]
}
And last but not least, the info data must be generated. This is done with
springBoot {
buildInfo {
properties {
additional = [
'description': 'This is the discovery server in the cloud'
]
}
}
}
A very important step: the git plugin must enable the full mode. This way, it will write the complete information about the git status into the git.properties files. And every field we’ll want to use must be there or it won’t show up.
management:
info:
git:
mode: full # Must be full so all fields are present in the git.properties file.