Printing the jar version using in the spring boot application in logs

Viewed 285

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

1 Answers

To only "print it (any "maven properties") to log":


  1. pom.xml:

    <properties>
      <foo>bar</foo>
      ...
    

    (this can be used throughout the pom...)

  2. application.properties:

    my.domain.someKey=@foo@
    
  3. Some bean referencing it as @Value("${my.domain.someKey})String foo.

  4. ...and logging it. (LOGGER.info(foo))

Refs:


A "production ready" (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:

Related