Reputation: 13203
I am using spring boot
and gradle
for my application. The application can have different versions
and we need to show this version info on the application in the footer.
e.g. 1.0.0 or 1.0.0.RELEASE etc
what are the possible ways to do this?
Upvotes: 4
Views: 8407
Reputation: 12734
There is a good example in the documentation. You can automatically expand properties from the Gradle project and refer those properties as placeholders in your application.properties
file.
processResources { expand(project.properties) }
You can then refer to your Gradle project’s properties via placeholders, e.g.
app.name=${name} app.description=${description}
You are then able to use for example the @Value
annotation to get the properties
value in your application.
@Value("${app.version}")
public String appVersion;
@Override
public void run(String... arg0) throws Exception {
System.out.println(appVersion);
}
Maybe you have to escape the placeholder mechanism:
Gradle’s expand method uses Groovy’s SimpleTemplateEngine which transforms
${..}
tokens. The${..}
style conflicts with Spring’s own property placeholder mechanism. To use Spring property placeholders together with automatic expansion the Spring property placeholders need to be escaped like\${..}
.
P.S.:With maven you can do the same. more...
Upvotes: 1