I have a spring boot application that uses gradle. I have configured gradle to inject build parameters into application.properties.
Here is my gradle snippet.
<I have the same problem - really annoying. Best solution I have found so far is to save a run/debug configuration in IntelliJ and then go in an edit the configuration, specifying that the gradle task processResources should be executed before launch.
I've resolved this by adding into application.yml the following:
${version?:unknown}
It also work from cli:gradle bootRun and also from IntelliJ and you don't have to call the Gradle task processResources before launching in IntelliJ or use spring profiles.
This work with Gradle ver:4.6 and also Spring Boot ver: 2.0.1.RELEASE.
Hope it helps ;)
I solve this with Spring profiles. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html
In application.properties I have
service.version=dev
In application-production.properties I have
service.version=${version}
And finally this in the build.gradle file
processResources {
filesMatching('application-production.properties') {
expand(project.properties)
}
}
In dev, test and integration tests the version will be "dev", when running with the production profile it will use the build version.
This also works when running the application directly from IntelliJ.