Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting application version from pom

I have a rest endpoint used to return information about application (so far only app version) But so far this info is hardcoded, and it's pretty easy to forget to change it. I will be better to retrieve app version from pom or manifest file. Is there any project that brings such functionality?

like image 306
marek.kapowicki Avatar asked Jan 10 '14 12:01

marek.kapowicki


People also ask

How do I get the app version in spring boot?

There are a few ways to get your application version with Spring Boot. One approach is using Maven resource filtering to add the version number as an enviroment variable in the application. yml during the build. Another approach is to use the Implementation-Version stored in the manifest file.

What is version in POM?

The version number of the artifact defined in the POM file is the same as the version number of the released product, for example 12.1. 2.0. 0, expressed using five digits, as described in the following: In x.x.x-y-z : x.x.x is the release version number, for example 12.1.

How do you find the value of POM files?

The plugin is part of the Maven Super Pom and executed during the process-resources phase of the Jar Default Lifecyle. The only thing you have to do is to active filtering. How you make this property then available to your Java application is up to you - reading it from the classpath would work.


1 Answers

Spring Boot can refer to the project version defined in pom.xml and expose it via REST using Actuator:

# application.properties
endpoints.info.enabled=true
[email protected]@

Then accessing the /info URL (e.g. http://localhost:8080/info) will return:

{"app": {"version": "<major.minor.incremental>"}}

See also: spring boot/spring web app embedded version number

like image 153
AlexO Avatar answered Sep 25 '22 16:09

AlexO