Search code examples
spring-bootbuild

Spring Boot build time always the same at /actuator/info


I have a "Hello World" Spring Boot app, with which I use for prototyping, study, etc.

I have noticed that the build time, as reported by Actuator (at http://localhost:8080/actuator/info) is always the same, namely: 1980-02-01T00:00:00Z.

What explains this?

If it was 1st Jan 1970, this would be slightly more understandable.

It is the same value as found in target/classes/META-INF/build-info.properties

$ cat target/classes/META-INF/build-info.properties
build.artifact=springboot
build.group=example
build.name=Spring Boot
build.time=1980-02-01T00\:00\:00Z
build.version=1.0.0-SNAPSHOT

The Maven plugin which creates this file is configured simply thus:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

UPDATE

I have one possible clue giving a hypothesis as to why this might be happening:

I have set up a Maven profile which uses spring-boot-maven-plugin with the goal build-image-no-fork and image.name as ${project.artifactId}:${project.version}.${buildNumber}.

This configures Spring to build a Docker image, rather than with a Dockerfile. From this I find:

$ docker images
springboot 1.0.0-SNAPSHOT.193 d703888fff79 45 years ago 352MB

$ docker inspect springboot:1.0.0-SNAPSHOT.193 | grep Created
        "Created": "1980-01-01T00:00:01Z",

The problem with this hypothesis is that 1980-02-01T00\:00\:00Z is one month and a second off from 1980-01-01T00:00:01Z, which is weird.

Also, why this should affect the regular non-Docker Maven build, is something I can't explain.

From Buildpacks.io:

We achieve reproducible builds by “zeroing” various timestamps of the layers of the output image. When images are inspected they may have confusing creation times (eg. “40 years ago”).


Solution

  • I'm not sure how to do that but maybe it can help you generate a dynamic build.time during each build

    1 ) Define build time value of Maven

    <properties>
        <maven.build.timestamp>${maven.build.timestamp}</maven.build.timestamp>
    </properties>
    

    2 ) Add value to the defined plugin

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>build-info</id>
                <goals>
                    <goal>build-info</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <additionalProperties>
                <build.time>${maven.build.timestamp}</build.time>
            </additionalProperties>
        </configuration>
    </plugin>