From 9c8a2a0b296ea4d604200630498604d4386287da Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 24 Jun 2021 18:58:24 +0200 Subject: [PATCH] Make builds reproducible --- build.gradle | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 32475846..63503b1f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,3 @@ -import java.text.SimpleDateFormat - buildscript { repositories { @@ -55,11 +53,16 @@ allprojects { mavenCentral() } + // Reproducible Builds + tasks.withType(AbstractArchiveTask) { + preserveFileTimestamps = false + reproducibleFileOrder = true + } + project.ext { junitVersion = '5.7.1' rootConfigDir = new File(rootDir, 'config') gitCommit = getGitCommit() - builtDate = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date()) isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI')) isReleaseVersion = !isSnapshot signingRequired = !(isSnapshot || isContinuousIntegrationEnvironment) @@ -188,9 +191,10 @@ subprojects { doLast { def propertiesFile = file "$generatedVersionDir/version.properties" propertiesFile.parentFile.mkdirs() - def properties = new Properties() - properties.setProperty("version", rootProject.version.toString()) - propertiesFile.withWriter { properties.store(it, null) } + propertiesFile.createNewFile() + // Instead of using a Properties object here, we directly write to the file + // since Properties adds a timestamp, ruining reproducibility + propertiesFile.write("version="+rootProject.version.toString()) } } processResources.dependsOn generateVersionProperties