all4u
all4u

Reputation: 11

Display Build time in spring boot /info endpoint

I have the below properties configured in my spring boot application.yml

info:
  app:
    name: @project.artifactId@
    description: @project.description@
    version: @project.version@
    timestamp: @timestamp@

After adding Spring Boot Actuator dependency, I am able to access /info endpoint and view the information.

To display the timestamp information, I add the below property in maven project's pom.xml as below,

<properties>
   <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
</properties>

The timestamp is displalyed in correct format but it is not correct one. I mean I am in IST timezone and the value is displayed as, timestamp: "2017-10-03T16:24:02Z" which is incorrect, probably it is displaying in GMT time format. But, I want IST format.

Can someone help me on this?

Upvotes: 0

Views: 5075

Answers (1)

glytching
glytching

Reputation: 48015

By default, Maven emits the maven.build.timestamp in UTC.

You can use the timestamp-property goal of the Maven Build Helper Plugin to emit a timestamp in a different timezone.

Here's an example:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>timestamp-property</id>
            <goals>
                <goal>timestamp-property</goal>
            </goals>
            <configuration>
                <name>build.timestamp.with.offset</name>
                <pattern>yyyy-MM-dd'T'HH:mm:ss'Z'</pattern>
                <timeZone>IST</timeZone>
            </configuration>
        </execution>
    </executions>
</plugin>

I've just run a build with that plugin in place and with the properties defined in your question and I'm echo'ing the values of both the timestamp property and the build.timestamp.with.offset property:

[INFO] Executing tasks
     [echo] [timestamp]: 2017-10-04T08:14:58Z
     [echo] [build.timestamp.with.offset]: 2017-10-04T12:44:59Z

This clearly shows that the default timestamp is in UTC and the build.timestamp.with.offset is in IST.

So, you could use this plugin and then update your application.yaml to use the build.timestamp.with.offset property.

Upvotes: 1

Related Questions