Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

What does a reproducible build mean for a Java project, and what usually prevents a Maven or Gradle build from producing identical bytes twice?

A reproducible build means that the same source code, built with the same declared environment, produces bit-for-bit identical artifacts, so anyone can rebuild a release and compare hashes. Maven and Gradle builds usually differ because of timestamps in jar entries, the order of files in the archive, build user, JDK or host details in the manifest, and unpinned dependency or plugin versions. Maven fixes timestamps with the project.build.outputTimestamp property, Gradle archive tasks use preserveFileTimestamps = false and reproducibleFileOrder = true, and we pin the JDK with toolchains and every plugin version.

Why this question is asked

If we build the same commit twice and get two jars with different SHA-256 hashes, we cannot prove that the jar in production came from the source we reviewed. Reproducible builds close that gap, and they also make caching, debugging and audits easier. Interviewers ask this question to see whether we understand what makes a build non-deterministic and know the specific settings in Maven and Gradle. In this answer, we will see what reproducibility means and how to test it, look at each common source of difference, fix them in Maven and in Gradle, and see what to pin besides the archive settings.

1What Reproducible Means, and How to Test It

A jar file is a zip archive. Two jars can contain exactly the same classes and still have different bytes, because the archive also stores metadata such as each entry's modification time and the order of entries. A build is reproducible when everything that goes into the archive is a function of the source and the declared environment only, so the bytes, and therefore the hash, are the same every time.

The test is simple: build twice, in different directories or on different machines, and compare hashes. Tools such as diffoscope show exactly which bytes differ, which is how we find the remaining causes.

Shell
git clone https://git.acme/orders a && git clone https://git.acme/orders b
(cd a && mvn -q -B package -DskipTests)
sleep 60
(cd b && mvn -q -B package -DskipTests)
sha256sum a/target/orders-4.2.1.jar b/target/orders-4.2.1.jar
# 3f9c...e1 a/target/orders-4.2.1.jar
# 7b20...4d b/target/orders-4.2.1.jar <- different, even with the same source
diffoscope a/target/orders-4.2.1.jar b/target/orders-4.2.1.jar | head
# zipinfo: entry times 2026-11-05 10:01 vs 10:02
# META-INF/MANIFEST.MF: Build-Jdk-Spec: 25 vs 21

2What Makes Two Builds Differ

The common causes are few, and each has a known fix. We can group them by where they enter the artifact.

Common sources of difference
SourceExampleFix
Entry timestampsEach file stamped with build timeFixed outputTimestamp; no preserved times
File orderFiles added in file system orderSorted, reproducible file order
Manifest detailsBuilt-By, Build-Jdk, host nameRemove, or pin the JDK so it is constant
Unpinned versionsPlugin or dependency ranges, LATESTPin every version; lock dependencies
Generated contentBuild date in a properties fileUse the commit time or remove it
Different JDKjavac output differs between versionsToolchains with an exact version

Notice that the first three come from how the archive is written, and the last three from what goes into it. The archive settings are a one-time change in the build configuration; the inputs need discipline across the project.

3Fixing It in Maven

Maven's standard plugins, from versions released around 2020 onwards, support reproducible builds through one property: project.build.outputTimestamp. When it is set, the jar, war, source and Javadoc plugins use it as the time of every entry instead of the current time, and they write entries in a stable order. The value is usually the time of the last commit, and the Maven release plugin updates it automatically on each release.

XML
<properties>
<!-- fixed time for every archive entry; updated by the release plugin -->
<project.build.outputTimestamp>2026-11-01T09:30:00Z</project.build.outputTimestamp>
</properties>
<!-- pin every plugin version, including the ones Maven adds by default -->
<build>
<pluginManagement>
<plugins>
<plugin><artifactId>maven-jar-plugin</artifactId><version>3.4.2</version></plugin>
<plugin><artifactId>maven-compiler-plugin</artifactId><version>3.14.0</version></plugin>
</plugins>
</pluginManagement>
</build>
// Build twice, then:
// mvn artifact:compare (maven-artifact-plugin) compares with a reference build
// sha256sum: 5d1e...a0 and 5d1e...a0 -> identical

The plugin versions above are examples; check the current ones. The point is that the versions are written down, so a build next year uses the same plugins. The Spring Boot parent already pins the standard plugins and supports outputTimestamp in its repackaging, which is one less thing to configure.

4Fixing It in Gradle

In Gradle, every task that writes an archive, such as jar, bootJar, zip and tar, extends AbstractArchiveTask, which has two properties for this. preserveFileTimestamps = false writes a fixed timestamp for every entry instead of each file's modification time, and reproducibleFileOrder = true sorts entries so their order does not depend on the file system. Gradle 9 makes these the default for archive tasks; on earlier versions we set them ourselves (check your version).

Java
// build.gradle.kts, or a shared convention plugin
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
java {
toolchain { languageVersion = JavaLanguageVersion.of(25) }
}
// Avoid build-time values in generated resources:
// bad: manifest { attributes("Build-Time" to java.time.Instant.now()) } // changes every build
// good: manifest { attributes("Implementation-Version" to project.version) }

Notice the manifest example. A Build-Time attribute is a common, well-meant addition that makes every build different. If we want build metadata, we take it from the commit, such as the commit hash and commit time, which are the same for every rebuild of that commit.

5Pinning the Toolchain and Every Version

Archive settings remove noise, but the content must also be the same. Different javac versions can produce different bytecode for the same source, so we pin the JDK with a toolchain at an exact major version, and in strict setups also the vendor and update version. Plugin versions must be pinned, because Maven otherwise falls back to defaults that change with the Maven version, and Gradle plugins without versions do not resolve at all. Dependency versions must not use ranges or dynamic versions such as 1.+ or LATEST; Gradle's dependency locking and a platform BOM in Maven keep resolution stable.

Finally, we build in a clean, defined environment, usually a CI container with a pinned image digest, so that environment variables, locale and time zone do not leak into generated files. With all of this in place, two builds a week apart, on two different machines, produce the same hash.

6Follow-up questions

Why does reproducibility matter if CI always builds the release?

Because it lets anyone verify CI's output. If a second, independent build of the same commit produces the same hash, a compromised CI agent that injected code would be detected. It also makes build caches more effective, since identical inputs produce identical outputs, and it lets us rebuild an old release years later and know it is the same artifact we shipped.

Is the Spring Boot fat jar reproducible?

It can be. The repackaging step adds the nested jars and the launcher classes, and recent Spring Boot plugins respect the same settings: outputTimestamp in Maven and the archive task properties for bootJar in Gradle. We still need the nested dependency jars themselves to be the same, which they are when versions are pinned, because they are downloaded unchanged from the repository.

What about layered jars and container images?

Container images have their own sources of difference, such as file times in layers and the image creation time. Tools such as Jib, and Spring Boot's buildpack integration, aim to produce reproducible images and set a fixed creation time by default (check your version). With a plain Dockerfile, we need to pin the base image by digest and avoid commands whose output changes over time.

7Conclusion

In this answer, we saw that a reproducible build produces bit-for-bit identical artifacts from the same source and environment, which we test by building twice and comparing hashes. The usual differences come from entry timestamps, file order, manifest details, unpinned versions, generated build-time values and different JDKs. Maven fixes the archive with project.build.outputTimestamp, Gradle with preserveFileTimestamps = false and reproducibleFileOrder = true, and toolchains plus pinned plugin and dependency versions make the content stable.

What to say in the interviewAbout 80 seconds aloud

Open with

A reproducible build means the same source, built in the same declared environment, gives bit-for-bit identical artifacts, so if I build a commit twice I get the same SHA-256.

Then, if they want more

I test it by building in two clean directories and comparing hashes, and diffoscope tells me what differs. The usual causes are in the archive and in the inputs.

A jar is a zip, so each entry has a timestamp, and the order of entries can follow the file system; the manifest can contain Built-By, the JDK version or a build time. On the input side, unpinned plugin or dependency versions, generated files with the build date, and a different JDK all change the output.

In Maven, the fix for the archive is the project.build.outputTimestamp property, which the standard plugins use for every entry, usually set to the last commit time and updated by the release plugin. In Gradle, archive tasks get preserveFileTimestamps = false and reproducibleFileOrder = true, which Gradle 9 makes the default.

Then I pin the JDK with toolchains, pin every plugin version, avoid version ranges or lock dependencies, and take any build metadata from the commit rather than the clock.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does a reproducible build mean for a Java project, and what usually prevents a...": https://scrivio-interview-library.netlify.app/java/dependency-and-supply-chain/16a960488d/