From 2dec6dd552395b35d7d22c86e4cbc436e390db53 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Thu, 22 Apr 2021 13:08:24 +0200 Subject: [PATCH 1/2] Reproducible build for spring-boot-maven-plugin:build-info See gh-26221 --- .../boot/maven/BuildInfoIntegrationTests.java | 9 ++++++ .../projects/build-info-reproducible/pom.xml | 31 +++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 24 ++++++++++++++ .../boot/maven/BuildInfoMojo.java | 8 +++-- 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/pom.xml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/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 b2d6bf15e8..c2461a1909 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 @@ -63,6 +63,15 @@ public class BuildInfoIntegrationTests { .hasBuildTime("2019-07-08T08:00:00Z"))); } + @TestTemplate + void generatedBuildInfoReproducible(MavenBuild mavenBuild) { + mavenBuild.project("build-info-reproducible") + .execute(buildInfo((buildInfo) -> assertThat(buildInfo) + .hasBuildGroup("org.springframework.boot.maven.it").hasBuildArtifact("build-reproducible") + .hasBuildName("Generate build info with build time from project.build.outputTimestamp") + .hasBuildVersion("0.0.1.BUILD-SNAPSHOT").hasBuildTime("2021-04-21T11:22:33Z"))); + } + @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/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/pom.xml new file mode 100644 index 0000000000..91edd4cbe0 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + org.springframework.boot.maven.it + build-reproducible + 0.0.1.BUILD-SNAPSHOT + Generate build info with build time from project.build.outputTimestamp + + UTF-8 + @java.version@ + @java.version@ + 2021-04-21T11:22:33Z + + + + + @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/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..ca2b9a2f0e --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2020 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 0b88685f70..94ff102465 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 @@ -69,11 +69,13 @@ public class BuildInfoMojo extends AbstractMojo { /** * The value used for the {@code build.time} property in a form suitable for - * {@link Instant#parse(CharSequence)}. Defaults to {@code session.request.startTime}. - * To disable the {@code build.time} property entirely, use {@code 'off'}. + * {@link Instant#parse(CharSequence)}. Defaults to + * {@code project.build.outputTimestamp} otherwise {@code session.request.startTime} + * if property is not set. To disable the {@code build.time} property entirely, use + * {@code 'off'}. * @since 2.2.0 */ - @Parameter + @Parameter(defaultValue = "${project.build.outputTimestamp}") private String time; /** From a1183c4641884e4519a6d022d248c282b87dd49f Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 31 May 2021 16:05:58 +0200 Subject: [PATCH 2/2] Polish "Reproducible build for spring-boot-maven-plugin:build-info" See gh-26221 --- .../src/intTest/projects/build-info-reproducible/pom.xml | 2 +- .../src/main/java/org/test/SampleApplication.java | 2 +- .../java/org/springframework/boot/maven/BuildInfoMojo.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/pom.xml index 91edd4cbe0..9e2114bf5a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/pom.xml +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot.maven.it build-reproducible diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/src/main/java/org/test/SampleApplication.java index ca2b9a2f0e..16c76e92c5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/src/main/java/org/test/SampleApplication.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible/src/main/java/org/test/SampleApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. 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 94ff102465..871d077e8c 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 @@ -70,8 +70,8 @@ public class BuildInfoMojo extends AbstractMojo { /** * The value used for the {@code build.time} property in a form suitable for * {@link Instant#parse(CharSequence)}. Defaults to - * {@code project.build.outputTimestamp} otherwise {@code session.request.startTime} - * if property is not set. To disable the {@code build.time} property entirely, use + * {@code project.build.outputTimestamp} or {@code session.request.startTime} if the + * former is not set. To disable the {@code build.time} property entirely, use * {@code 'off'}. * @since 2.2.0 */