How do you get build-info and git-info to appear under /actuator/info, and which beans back them?
answer
- build-info.properties <- spring-boot-maven-plugin build-info goal / buildInfo()
- git.properties <- git-commit-id / gradle-git-properties plugin
- BuildProperties + GitProperties beans via ProjectInfoAutoConfiguration
- management.info.git.mode = simple (default) vs full
- no plugin => empty block
basics
~20 sGenerate the metadata files at build time: the Spring Boot plugin's build-info goal creates META-INF/build-info.properties, and a git plugin creates git.properties. Spring Boot then auto-creates BuildProperties and GitProperties beans, and their contributors add build/git blocks.
solid answer
~40 sBoth blocks come from files generated at build time, not runtime introspection. For build-info you enable the Spring Boot plugin's build-info step (Maven: the spring-boot-maven-plugin build-info goal; Gradle: springBoot { buildInfo() }); it writes META-INF/build-info.properties (group, artifact, version, name, time). Spring Boot auto-configures a BuildProperties bean from it, and BuildInfoContributor emits the build block. For git-info you add a git plugin (Maven: git-commit-id-maven-plugin, managed by Boot; Gradle: gradle-git-properties) that writes git.properties. Spring Boot auto-configures GitProperties and GitInfoContributor emits the git block. By default git shows a simple subset (branch, commit id, commit time); set management.info.git.mode=full for everything. Both build and git contributors are enabled by default when their files/beans are present.
code
java · 15 lines// Maven pom.xml — generate BOTH metadata files
// <plugin> spring-boot-maven-plugin with <goal>build-info</goal>
// <plugin> io.github.git-commit-id:git-commit-id-maven-plugin
// You can also inject the beans Spring auto-configures:
@Component
class VersionLogger {
VersionLogger(BuildProperties build, GitProperties git) {
System.out.printf("Running %s v%s (commit %s)%n",
build.getName(), build.getVersion(), git.getShortCommitId());
}
}
// application.properties
// management.info.git.mode=full # optional: show the entire git.propertiesgo deeper
Know the two properties files exist and are generated by build plugins.
Name the plugins/goals and the BuildProperties/GitProperties beans and their contributors.
Explain git.mode, injecting the beans in code, and diagnosing missing blocks.
Weigh full git mode against information disclosure and standardize generation across the build pipeline.
## The key idea: build-time files, not runtime magic Neither `build` nor `git` info is discovered by reflection at runtime. Both are produced by **build plugins** that write small `.properties` files into the packaged jar; Spring Boot reads those files at startup into typed beans, and dedicated contributors surface them. ## build-info **Generate the file:** - **Maven** — bind the `build-info` goal of `spring-boot-maven-plugin`: ```xml <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution><goals><goal>build-info</goal></goals></execution> </executions> </plugin> ``` - **Gradle** — enable it in the `springBoot` block: ```groovy springBoot { buildInfo() } ``` Either way you get `META-INF/build-info.properties` containing `build.group`, `build.artifact`, `build.version`, `build.name`, `build.time`, plus any custom `additionalProperties`. **How Spring surfaces it:** `ProjectInfoAutoConfiguration` creates a `org.springframework.boot.info.BuildProperties` bean when `build-info.properties` is on the classpath. `BuildInfoContributor` (auto-configured, enabled by default via `management.info.build.enabled=true`) adds the `build` block. You can also inject `BuildProperties` directly for use in code (e.g. a version banner). ## git-info **Generate the file:** - **Maven** — `git-commit-id-maven-plugin` (group `io.github.git-commit-id`; Spring Boot manages its version). It writes `git.properties`. - **Gradle** — the `com.gorylenko.gradle-git-properties` plugin. `git.properties` holds keys like `git.branch`, `git.commit.id`, `git.commit.id.abbrev`, `git.commit.time`, `git.build.time`, etc. **How Spring surfaces it:** `ProjectInfoAutoConfiguration` creates a `org.springframework.boot.info.GitProperties` bean from `git.properties`; `GitInfoContributor` (enabled by default via `management.info.git.enabled=true`) adds the `git` block. **git.mode — how much to show:** controlled by `management.info.git.mode`: - `simple` (default): only `git.branch`, `git.commit.id` (abbreviated), and `git.commit.time`. - `full`: the entire contents of `git.properties`. ## Common gotchas - **Nothing appears** → you forgot the build plugin, so the properties file was never generated. This is the #1 cause of an empty `build`/`git` block. - **Works in IDE, missing in jar (or vice versa)** → file location/classpath differences; ensure the plugin runs in the package phase/task. - **Custom file path** → `BuildProperties`/`GitProperties` default to the standard locations; overriding requires configuring the auto-config or defining the bean yourself. - **git.properties can leak info** → `full` mode exposes remote URL, dirty flag, tags, user email; keep `simple` unless you control exposure (see security question). ## When to use Build + git info give operators an authoritative 'exactly what is deployed' answer (version + commit), invaluable for correlating a running instance with a source revision during incidents.
- Your /actuator/info shows a git block but no build block. What's the most likely cause?git.properties is being generated by the git plugin, but build-info.properties is not — you haven't enabled the spring-boot-maven-plugin build-info goal / Gradle buildInfo(), so no BuildProperties bean exists.
- What's the difference between git.mode=simple and full, and which is the default?simple (the default) exposes only branch, abbreviated commit id, and commit time; full exposes the entire git.properties including remote URL, tags, dirty flag, and committer details.
saying these in an interview costs you the question
- Thinking Spring reads git/build info from the runtime environment rather than generated files
- Believing build/git blocks appear just by adding the actuator starter
- Saying git.mode defaults to full
- Confusing BuildProperties (build-info.properties) with GitProperties (git.properties)