Getting app version from pom

I have a rest point used to return information about the application (so far only the version of the application) But so far this information is hard-coded and it is quite easy to forget to change it. I would be better off getting the version of the application from the pom or manifest file. Is there any project that brings such functionality?

+8
java spring maven versioning
source share
4 answers

There is an amazing project called Appinfo , please use it and enjoy! (It has an ugly page, I know - but it works :)

AppInfo allows you to automatically submit your application with the current version number, build date, or build number.


Also, the excellent Spring Boot Actuator provides a feature called Info Endpoint that can publish version information on the Internet or REST.

By default, Actuator adds the / info endpoint to the primary server. It contains information about the commit and timestamp from git.properties (if this file exists), as well as any properties that it finds in the environment with the prefix "information".

+4
source share

Better to use assembly manifest.

new Manifest(Application.class.getResourceAsStream("/META-INF/manifest.mf")) 

For a specific impl version:

 new Manifest(Application.class.getResourceAsStream("/META-INF/manifest.mf")) .getMainAttributes() .get(Attributes.Name.IMPLEMENTATION_VERSION) 

Using maven, don't forget to create a manifest using:

 <?xml version="1.0" encoding="UTF-8"?> <project> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project> 
+8
source share

Spring Download can reference the version of the project defined in pom.xml and expose it through REST using Actuator :

 # application.properties endpoints.info.enabled=true info.app.version=@project.version@ 

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

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

See also: Spring boot / spring number of the embedded version of the web application

+3
source share

You can use maven resource filtering or something like maven-substitute-plugin .

+2
source share

All Articles