Support AbstractArchiveTask.preserveFileTimestamps for reproducible builds #391
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this PR, the officially recommended Gradle config for reproducible builds now successfully creates reproducible builds when used with shadowJar:
Gradle 3.4 added support for reproducible builds of archives, but shadowJar doesn't respect the preserveFileTimestamps setting despite extending AbstractArchiveTask which exposes that. This PR makes the shadowJar task handle the preserveFileTimestamps setting. (I believe the reproducibleFileOrder setting is handled by Gradle in a way that already works for shadowJar.)
Solves #229 and #389.
The implementation and choice of the default constant timestamp are inspired by Gradle's own ZipCopyAction class.
This does make the plugin incompatible with versions of Gradle before 3.4. I think I could change the PR to use reflection to read the preserveFileTimestamps value if backwards compatibility with those versions was considered important.
I know that the inspiration for #333 was to allow a user to configure build.gradle to zero out timestamps, but I don't think this PR is redundant with it: this PR adds support to shadowJar for the standard Gradle configuration for reproducible builds without adding any new shadow APIs.