Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Gradle.build version into Spring Boot

Tags:

I'm trying to display the application version of my Spring Boot application in a view. I'm sure I can access this version information, I just don't know how.

I tried following this information: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html, and put this in my application.properties:

info.build.version=${version} 

And then loading it @Value("${version.test}") in my controller, but that doesn't work, I only get errors like:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'version' in string value "${version}" 

Any suggestions on what the proper way to get information like my app version, the spring boot version, etc into my controller?

like image 377
Erik Pragt Avatar asked Jan 23 '16 11:01

Erik Pragt


People also ask

How do I change the Gradle version in spring boot?

You are going to need to update gradle, as newer spring boot versions are incompatible with older versions of gradle. You can either download the new gradle manually or use gradle wrapper to set the version for your project.

How do I find Gradle version in build Gradle?

In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.

Where is build Gradle file in spring boot?

Clean & Build Gradle Spring Boot Application It will create jar file at \build\libs.

What is build Gradle in spring boot?

Introduction. The Spring Boot Gradle Plugin provides Spring Boot support in Gradle. It allows you to package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by spring-boot-dependencies . Spring Boot's Gradle plugin requires Gradle 6.8, 6.9, or 7.


1 Answers

You can also add this in build.gradle :

springBoot {         buildInfo()  } 

Then, you can use BuildProperties bean :

@Autowired private BuildProperties buildProperties; 

And get the version with buildProperties.getVersion()

like image 165
Clément Poissonnier Avatar answered Sep 30 '22 15:09

Clément Poissonnier