# Spring Boot Actuator show the git and build info

# Introduction

The git and build information can help us for troubleshooting and version control. With Spring Boot Actuator, we can fetch the info just by adding the plugins.

# Integration

Add the actuator dependency:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Enable the actuator endpoint:

management:
  endpoints:
    web:
      exposure:
        include: "*"

now can access /actuator/info, but the response will be empty.

If we need the git and build info, we need to add maven plugin to generate the properties file:

<plugins>
  <plugin>
    <groupId>pl.project13.maven</groupId>
    <artifactId>git-commit-id-plugin</artifactId>
    <version>4.0.0</version>
    <executions>
      <execution>
        <id>get-the-git-infos</id>
        <goals>
          <goal>revision</goal>
        </goals>
        <phase>initialize</phase>
      </execution>
    </executions>
    <configuration>
      <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
      <generateGitPropertiesFile>true</generateGitPropertiesFile>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring-boot-dependencies.version}</version>
    <executions>
      <execution>
        <goals>
          <goal>build-info</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>

After we run the maven build, it will generate two files for us, one is build-info.properties, another is git.properties:

Now we can restart the application and access the /actuator/info again:

# Code

Code on GitHub: https://github.com/LarryDpk/pkslow-samples


Reference:

Provide Spring Boot git and build information via /actuator/info endpoint when using maven as a build tool (opens new window)

GitHub git-commit-id-maven-plugin (opens new window)

using-the-plugin (opens new window)

Last Updated: 8/18/2023, 11:39:36 PM