diff --git a/build.gradle b/build.gradle index 4be3ce4e53cd0..91472a62a2bd9 100644 --- a/build.gradle +++ b/build.gradle @@ -274,6 +274,14 @@ allprojects { javadoc.options.addStringOption('Xdoclint:all,-missing', '-quiet') } + // support for reproducible builds + tasks.withType(AbstractArchiveTask).configureEach { + // ignore file timestamps + // be consistent in archive file order + preserveFileTimestamps = false + reproducibleFileOrder = true + } + project.afterEvaluate { // Handle javadoc dependencies across projects. Order matters: the linksOffline for // org.opensearch:opensearch must be the last one or all the links for the diff --git a/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java index 60afe8334f05d..ccd82372bb11b 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java @@ -121,7 +121,7 @@ public void apply(Project project) { params.setGradleJavaVersion(Jvm.current().getJavaVersion()); params.setGitRevision(gitInfo.getRevision()); params.setGitOrigin(gitInfo.getOrigin()); - params.setBuildDate(ZonedDateTime.now(ZoneOffset.UTC)); + params.setBuildDate(Util.getBuildDate(ZonedDateTime.now(ZoneOffset.UTC))); params.setTestSeed(getTestSeed()); params.setIsCi(System.getenv("JENKINS_URL") != null); params.setIsInternal(isInternal); diff --git a/buildSrc/src/main/java/org/opensearch/gradle/util/Util.java b/buildSrc/src/main/java/org/opensearch/gradle/util/Util.java index fc79d991211d6..71b1e5040340d 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/util/Util.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/util/Util.java @@ -48,6 +48,9 @@ import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.Locale; import java.util.Optional; import java.util.function.Supplier; @@ -187,4 +190,17 @@ public String toString() { } }; } + + public static ZonedDateTime getBuildDate(ZonedDateTime defaultValue) { + final String sourceDateEpoch = System.getenv("SOURCE_DATE_EPOCH"); + if (sourceDateEpoch != null) { + try { + return ZonedDateTime.ofInstant(Instant.ofEpochSecond(Long.parseLong(sourceDateEpoch)), ZoneOffset.UTC); + } catch (NumberFormatException e) { + throw new GradleException("Sysprop [SOURCE_DATE_EPOCH] must be of type [long]", e); + } + } else { + return defaultValue; + } + } } diff --git a/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java index 1296532b0ba0d..d20b151bb69bf 100644 --- a/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java @@ -55,7 +55,6 @@ import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LiveIndexWriterConfig; -import org.apache.lucene.index.LogByteSizeMergePolicy; import org.apache.lucene.index.LogDocMergePolicy; import org.apache.lucene.index.MergePolicy; import org.apache.lucene.index.NoMergePolicy;