Skip to content

Commit 5c94a98

Browse files
committed
Restore support for SOURCE_DATE_EPOCH env var
1 parent 3be8a00 commit 5c94a98

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

gradle/plugins/build-parameters/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ buildParameters {
7070
}
7171
group("manifest") {
7272
string("buildTimestamp") {
73-
description = "Overrides the value of the 'Build-Date' and 'Build-Time' jar manifest entries (e.g. '2023-11-05 17:49:13.996+0100')."
73+
description = "Overrides the value of the 'Build-Date' and 'Build-Time' jar manifest entries. Can be set as a String (e.g. '2023-11-05 17:49:13.996+0100') or as seconds since the epoch."
74+
fromEnvironment("SOURCE_DATE_EPOCH") // see https://reproducible-builds.org/docs/source-date-epoch/
7475
}
7576
string("builtBy") {
7677
description = "Overrides the value of the 'Built-By' jar manifest entry"

gradle/plugins/common/src/main/kotlin/junitbuild.build-metadata.gradle.kts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import java.time.Instant
12
import java.time.OffsetDateTime
3+
import java.time.ZoneOffset
24
import java.time.format.DateTimeFormatter
35
import java.time.format.DateTimeFormatterBuilder
46

@@ -11,12 +13,14 @@ val timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ")
1113

1214
val buildTimeAndDate = buildParameters.manifest.buildTimestamp
1315
.map {
14-
DateTimeFormatterBuilder()
15-
.append(dateFormatter)
16-
.appendLiteral(' ')
17-
.append(timeFormatter)
18-
.toFormatter()
19-
.parse(it)
16+
it.toLongOrNull()
17+
?.let { s -> Instant.ofEpochSecond(s).atOffset(ZoneOffset.UTC) }
18+
?: DateTimeFormatterBuilder()
19+
.append(dateFormatter)
20+
.appendLiteral(' ')
21+
.append(timeFormatter)
22+
.toFormatter()
23+
.parse(it)
2024
}
2125
.orNull
2226
?: OffsetDateTime.now()

gradle/scripts/checkBuildReproducibility.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
rm -rf checksums*
44

5-
BUILD_TIMESTAMP=$(date -Iseconds)
5+
export SOURCE_DATE_EPOCH=$(date +%s)
66

77
function calculate_checksums() {
88
OUTPUT=$1
99

1010
./gradlew \
11+
--configuration-cache \
1112
--no-build-cache \
1213
-Porg.gradle.java.installations.auto-download=false \
1314
-Dscan.tag.Reproducibility \
14-
-Pmanifest.buildTimestamp="${BUILD_TIMESTAMP}" \
1515
clean \
1616
assemble
1717

0 commit comments

Comments
 (0)