Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Actuator Info Endpoint Version from Gradle File

I'd like the /info actuator endpoint from my Spring Boot (1.2.4.RELEASE) application to return the version as specified in the build.gradle file.

In my build.gradle file I have a line as so:

version = '0.0.1-SNAPSHOT'

I am using yaml configuration file. Right now I have the version duplicated as so in application.yml:

info:
    build:
        version: 0.0.1-SNAPSHOT  

Is this possible?

like image 699
Steve Avatar asked Sep 03 '25 17:09

Steve


1 Answers

Add the following to the build.gradle file. It is not necessary to create an InfoContributor class.

plugins {
  id 'org.springframework.boot' version '<version>'
}

springBoot {
  buildInfo()
}

dependencies {
  implementation 'org.springframework.boot:spring-boot-starter-actuator'
    etc...
}

Query http://host:port/actuator/info and you will see something like...

{
  "build": {
    "artifact": "spring-example",
    "name": "spring-example",
    "time": "2020-01-30T09:47:33.551Z",
    "version": "0.0.1-SNAPSHOT",
    "group": "com.example"
  }
}

N.b. Tested with 2.2.4.RELEASE

like image 133
Kevvvvyp Avatar answered Sep 05 '25 14:09

Kevvvvyp