-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow overriding JAR manifest entries for reproducibility
With these changes, the `Build-Date`, `Build-Time`, and `Created-By` manifest entries can be taken from the released JARs and passed to the build in order to check for reproducibility: ./gradlew assemble \ -Pmanifest.buildTimestamp='2024-01-07 14:00:54.292+0100' \ -Pmanifest.createdBy='21.0.1 (BellSoft 21.0.1+12-LTS)' Closes #3559.
- Loading branch information
1 parent
f53e690
commit 2a4326b
Showing
5 changed files
with
42 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 18 additions & 16 deletions
34
gradle/plugins/common/src/main/kotlin/junitbuild.build-metadata.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import java.time.Instant | ||
import java.time.OffsetDateTime | ||
import java.time.ZoneOffset | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.DateTimeFormatterBuilder | ||
|
||
val buildTimeAndDate = | ||
if (System.getenv().containsKey("SOURCE_DATE_EPOCH")) { | ||
|
||
// SOURCE_DATE_EPOCH is a UNIX timestamp for pinning build metadata against | ||
// in order to achieve reproducible builds | ||
// | ||
// More details - https://reproducible-builds.org/docs/source-date-epoch/ | ||
val sourceDateEpoch = System.getenv("SOURCE_DATE_EPOCH").toLong() | ||
plugins { | ||
id("junitbuild.build-parameters") | ||
} | ||
|
||
Instant.ofEpochSecond(sourceDateEpoch).atOffset(ZoneOffset.UTC) | ||
val dateFormatter = DateTimeFormatter.ISO_LOCAL_DATE | ||
val timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ") | ||
|
||
} else { | ||
OffsetDateTime.now() | ||
val buildTimeAndDate = buildParameters.manifest.buildTimestamp | ||
.map { | ||
DateTimeFormatterBuilder() | ||
.append(dateFormatter) | ||
.appendLiteral(' ') | ||
.append(timeFormatter) | ||
.toFormatter() | ||
.parse(it) | ||
} | ||
.orNull | ||
?: OffsetDateTime.now() | ||
|
||
val buildDate: String by extra { DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate) } | ||
val buildTime: String by extra { DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ").format(buildTimeAndDate) } | ||
val buildDate: String by extra { dateFormatter.format(buildTimeAndDate) } | ||
val buildTime: String by extra { timeFormatter.format(buildTimeAndDate) } | ||
val buildRevision: String by extra { | ||
providers.exec { | ||
commandLine("git", "rev-parse", "--verify", "HEAD") | ||
}.standardOutput.asText.get() | ||
} | ||
val builtByValue by extra { project.findProperty("builtBy") ?: project.property("defaultBuiltBy") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2a4326b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍