spring-boot: project.version not accessible in application.properties with gradle build
In the docs here there is mention of using syntax like this this in application.properties to access a version number via actuator:
info.build.version=${project.version}
When using gradle, the project.version does not seem to be populated though, resulting in actuator just printing the “${project.version}” characters, not resolving the code to the version.
For the sake of testing that these variables can be resolved, I also tested this and it worked fine:
info.build.random=${random.long}
The docs state that this is a Spring Boot Maven feature, but I was hoping it would work for Gradle too. Is this expected to work for Gradle or is there an alternative perhaps?
If it’s of any help, here it my build.gradle file contents:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.1.5.RELEASE')
}
}
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'spring-boot'
dependencies {
// tag::jetty[]
compile('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'spring-boot-starter-tomcat'
}
compile('org.springframework.boot:spring-boot-starter-jetty')
// end::jetty[]
// tag::actuator[]
compile('org.springframework.boot:spring-boot-starter-actuator')
// end::actuator[]
}
version = '1.0.0'
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- Updating sqldb-service to data-service with webflux services — committed to pranav-patil/spring-microservices by pranav-patil 6 years ago
@pnowy an example showing the values used in each of the following files would be really helpful please,
For my reference: if the
${...}parentheses are causing “Could not resolve placeholder” errors, you can alternatively use<%=...%>. N.B. tested with a *.properties file, not sure how this would work for an XML file.That’s by design.
bootRunis intended for use at development time. As described in the documentationsrc/main/resourcesis used, rather than resources that have been “built”, so that resources are reloadable. If you build your application and run its jar file, you should see that the resource has been processed and the properties expanded.Gradle has an equivalent. You need to add property expansion to the Java plugin’s existing
processResourcestask:You can then reference any of the project’s properties in your resources and they’ll be expanded. For example:
See section 16.6.2 of Gradle’s documentation for some more information.
It’s closed but maybe it will be useful for someone. Everything what I need to to (Gradle 3.1, SpringBoot 1.4.1) was:
It works both for Intellij IDEA and run by JAR file.