From bf881e507dfe3f7a46903b959706d9ac57f41de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20H=C3=B6hmann?= Date: Tue, 29 Oct 2024 10:29:19 +0100 Subject: [PATCH] fix(maven): buildinfo doesn't support seconds since the epoch Use MavenBuildOutputTimestamp inside BuildInfoMojo to create Instant from project.build.outputTimestamp where the value of this property is in just epoch seconds. --- .../boot/maven/BuildInfoIntegrationTests.java | 10 ++++++ .../pom.xml | 32 +++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 24 ++++++++++++++ .../boot/maven/BuildInfoMojo.java | 2 +- 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java index 036aa6912d34..9dd8f1b8b65a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java @@ -83,6 +83,16 @@ void generatedBuildInfoReproducible(MavenBuild mavenBuild) { .hasBuildTime("2021-04-21T11:22:33Z"))); } + @TestTemplate + void generatedBuildInfoReproducibleEpochSeconds(MavenBuild mavenBuild) { + mavenBuild.project("build-info-reproducible-epochseconds") + .execute(buildInfo((buildInfo) -> assertThat(buildInfo).hasBuildGroup("org.springframework.boot.maven.it") + .hasBuildArtifact("build-reproducible-epochseconds") + .hasBuildName("Generate build info with build time from project.build.outputTimestamp") + .hasBuildVersion("0.0.1.BUILD-SNAPSHOT") + .hasBuildTime("1976-01-09T12:00:00Z"))); + } + @TestTemplate void buildInfoPropertiesAreGeneratedToCustomOutputLocation(MavenBuild mavenBuild) { mavenBuild.project("build-info-custom-file") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml new file mode 100644 index 000000000000..5a8aa26d4d2e --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + org.springframework.boot.maven.it + build-reproducible-epochseconds + 0.0.1.BUILD-SNAPSHOT + Generate build info with build time from project.build.outputTimestamp + + UTF-8 + @java.version@ + @java.version@ + + 190036800 + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + build-info + + + + + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java new file mode 100644 index 000000000000..1277cdbc5a63 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.test; + +public class SampleApplication { + + public static void main(String[] args) { + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java index bef8512f2820..720f0e4db0cd 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java @@ -154,7 +154,7 @@ private Instant getBuildTime() { if ("off".equalsIgnoreCase(this.time)) { return null; } - return Instant.parse(this.time); + return new MavenBuildOutputTimestamp(this.time).toInstant(); } }