Skip to content

Conversation

DPUkyle
Copy link
Contributor

@DPUkyle DPUkyle commented Feb 9, 2023

Configures Maven to create bit-by-bit reproducible artifacts.

As with Gradle and Bnd, timestamps in jars are normalized to 1980 February 1st CET. This is not without controversy, as shown by this example issue: FasterXML/jackson-databind#3680

An alternative albeit slightly more complex approach is to update project.build.outputTimestamp at release time, as shown in this FAQ: https://maven.apache.org/guides/mini/guide-reproducible-builds.html#faq

Finally, for reference purposes I've used the excellent diffoscope tool to create a visual diff of guava-31.1-jre release vs. the same code built with this change. Open index.html in this archive: guava-diff.zip

Steps to reproduce the above:

  1. $ git checkout v31.1
  2. $ git cherry-pick ### # the commit of this PR
  3. $ mvn clean install -U -DskipTests=true
  4. $ curl https://repo1.maven.org/maven2/com/google/guava/guava/31.1-jre/guava-31.1-jre.jar --output ~/Downloads/guava-31.1-jre.jar # sha1sum should be 60458f877d055d0c9114d9e1a2efb737b4bc282c
  5. $ diffoscope --exclude \*.class --html-dir guava-diff ~/Downloads/guava-31.1-jre.jar guava/target/guava-31.1-jre.jar

The important things to notice in the diff:

  • LHS is the released v31.1 jar; RHS is the output of building with this PR
  • zipinfo output shows normalized timestamps in the zip catalog on RHS
  • META-INF/MANIFEST.MF: Problematic Bnd-LastModified and Built-By attributes are gone. Different Tool version is used by maven-bundle-plugin.
  • META-INF/**/pom.properties: Problematic comment with timestamp is gone

Note that in step 5 I excluded class files from analysis; that's because diffoscope delegates to a decompiler which seemed confused about inlined Strings and lambdas, creating false-positives. I suspect this is a difference between my local JDK and/or vendor vs. the released artifact.

NB: There appear to be other past changes related to reproducible builds: #3534, #3681 and #3686

 - Enable class file timestamp normalization by bumping to latest version of maven-bundle-plugin
   - See changes at apache/felix-dev@957e5c9, available from
plugin 5.1.3 and later

 - Make build artifacts bit-for-bit reproducible by normalizing timestamp
   - maven-bundle-plugin reacts to this value with desirable side-effect of removing timestampts from OSGi bundle/jar
manifests and pom.properties files
   - Uses the same normalization schemes as Gradle and Bnd:
     - https://github.com/gradle/gradle/blob/v7.6.0/subprojects/core/src/main/java/org/gradle/api/internal/file/archive/ZipCopyAction.java#L57
     - https://github.com/bndtools/bnd/blame/a6aed533455f43e8a3802f847e8f6548a868f922/biz.aQute.bndlib/src/aQute/bnd/osgi/Jar.java#L71-L87
@DPUkyle DPUkyle force-pushed the km/make-reproducible branch from 1247939 to ade03d2 Compare February 9, 2023 01:26
@DPUkyle
Copy link
Contributor Author

DPUkyle commented Feb 9, 2023

@eamonnmcmanus I'm not done documenting this PR, but can you enable me to run CI workflows?

@DPUkyle DPUkyle marked this pull request as ready for review February 9, 2023 02:41
@DPUkyle DPUkyle changed the title [DRAFT: do not review] Create reproducible artifacts Create reproducible artifacts Feb 9, 2023
@eamonnmcmanus
Copy link
Member

Looking good! Thanks very much for doing this. Because the Source Of Truth for Guava is actually Google's internal repository, we'll make the change there and it will appear as a separate PR that will close this one. You will be duly credited, of course.

@eamonnmcmanus eamonnmcmanus self-assigned this Feb 9, 2023
copybara-service bot pushed a commit that referenced this pull request Feb 9, 2023
As with Gradle and Bnd, timestamps in jars are [normalized](https://github.com/gradle/gradle/blob/v7.6.0/subprojects/core/src/main/java/org/gradle/api/internal/file/archive/ZipCopyAction.java#L57) to 1980 February 1st CET.

Closes #6322.

RELNOTES=n/a
PiperOrigin-RevId: 508455012
@copybara-service copybara-service bot closed this in a9a2e95 Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants