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 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.