Is it possible to print the version of the jar we are using the pom.xml in logs.
For example, I'm using the Jar aspose-email in the application, I want to print the version whichever I'm using in logs.
If possible, how to do it
Is it possible to print the version of the jar we are using the pom.xml in logs.
For example, I'm using the Jar aspose-email in the application, I want to print the version whichever I'm using in logs.
If possible, how to do it
To only "print it (any "maven properties") to log":
pom.xml:
<properties>
<foo>bar</foo>
...
(this can be used throughout the pom...)
application.properties:
my.domain.someKey=@foo@
Some bean referencing it as @Value("${my.domain.someKey})String foo.
...and logging it. (LOGGER.info(foo))
Refs:
Note: Since the application.properties and application.yml files accept Spring style placeholders (
${…}), the Maven filtering is changed to use@..@placeholders. (You can override that by setting a Maven property calledresource.delimiter.)
A "production ready" spring-boot (web exposure) approach:
Assuming this spring-boot-starter(web,actuator).
We add this to our application.properties:
# we need this (jmx is exposed by default):
management.endpoints.web.exposure.include=info
# ... and this (enables info.* properties):
management.info.env.enabled=true
# ...then can write here arbitrary values, starting with info.*
info.foo=foo
# ...or "filtered" from the pom, like e.g:
info.app.spring-boot.version=@project.parent.version@
# we can use here also any pom.properties like @my.property@
# for pessimistic enablement/opt out:
#management.endpoints.enabled-by-default=false
#management.endpoint.info.enabled=true
And find them at http://localhost:8080/actuator/info , like:
{"foo":"foo","app":{"spring-boot":{"version":"2.6.2"}}}
Refs: