2

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?

foo=@project.artifactId@-sew2-san-@build.artifact@-${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?

bastiat
  • 1,799
  • 2
  • 19
  • 38
  • Why do you like to do that? Why do you need build information in your `application.properties` and for what purpose? – khmarbaise Oct 20 '21 at 14:48
  • @khmarbaise I would like to use ${build.name} as part of another property (some label) in application.properties eg some.label=${env}-${build.name}-label – bastiat Oct 21 '21 at 12:59

1 Answers1

2

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)

Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70