Issue
How can I use properties from build-info.properties in application.properties?
pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
build-info.properties is correctly generated:
cat app/target/classes/META-INF/build-info.properties
build.artifact=foo-app
build.group=org.springframework.boot
build.name=foo-app
build.time=2021-10-13T12\:46\:08.326Z
build.version=9.9.0-9-5f12d7cd-bugfix_bar_3123_branch_name_123-dirty
How can I use them i application.properties?
[email protected]@[email protected]@-${build.artifact}
only @project.artifactId@ is resolved, neither @build.artifact@ nor ${build.artifact} is resolved.
Is it possible to use properties from build-info.properties in application.properties?
Solution
If you add:
spring.config.import=classpath:META-INF/build-info.properties
to your application.properties
file then interpolation with an expression like ${build.artifact}
will start to work.
(Spring is loading build-info.properties with a weird manual way as you can see e.g. here https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.java)
Answered By - Ondrej Bozek
Answer Checked By - Willingham (JavaFixing Volunteer)