After some research and trials on how to get the Maven project version in a SpringBoot application I couldn't find anything working for me.
Using a manifest is definitively a rotten path due to class loaders issues, i.e. one gets the first manifest Spring finds, which in my case was not the one of my application.
One solution I have found is to use the maven resources plugin to "filter" (replace) properties in resource files. In this case the Spring application.properties.
Below are the steps to make this work.
In the pom file, activate resources filtering with the following definition:
Notice the @property@ instead of ${property}. in the application.properties file.
The spring-boot-starter-parent pom redefines the standard ${} delimiter as @:
<resource.delimiter>@</resource.delimiter>
<!-- delimiter that doesn't clash with Spring ${} placeholders -->
<delimiters>
<delimiter>${resource.delimiter}</delimiter>
</delimiters>
One can then access those properties in Spring using @Value like this:
It's probably because your main pom doesn't declare spring-boot-starter-parent as its parent pom.
Because when so, the filtering is done by default, without needing to declare the filtering explicitly
There a easier way to do this, don't need to add application.properties or delimiter changes.
Simply add plugin with goal build-info and Autowire start up class with bean BuildProperties.