Optimize normalizeJar memory footprint and preserve entry metadata - #2164
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the post-R8 jar “normalization” step so Shadow can rewrite R8’s output jar while preserving important entry metadata and avoiding loading entire entry contents into memory.
Changes:
- Rework
R8Minimizer.normalizeJarto stream entry bytes from the input zip instead of materializing them, and preserve each entry’s Unix mode. - Ensure
META-INF/MANIFEST.MFis written as the first file entry in the normalized jar. - Add a focused regression test validating manifest ordering and executable permissions preservation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/R8MinimizerTest.kt |
Adds coverage for manifest-first ordering and Unix mode preservation during normalization. |
src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Zip.kt |
Adds UnixMode.raw(...) to allow writing preserved Unix modes verbatim. |
src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/R8Minimizer.kt |
Streams jar normalization, preserves Unix permissions, and forces manifest to be first file entry. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.kt:139
ShadowCopyActionstill accepts anencodingparameter, but the StreamAction no longer applies it to the providedZipOutputStream. This makes theencodingargument ineffective for callers that provide a customzosProvider, which is a behavioral/API regression.
private inner class StreamAction(private val zipOutStr: ZipOutputStream) :
CopyActionProcessingStreamAction {
init {
logger.info("Relocator count: {}.", relocators.size)
}
src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/R8MinimizerTest.kt:71
- The test will currently fail with an NPE if the entry is missing, which obscures the cause. Adding an explicit null check gives a clearer failure message.
ZipFile(outputJar).use { zipFile ->
// Executable unix mode must be preserved
val scriptEntry = zipFile.getEntry("bin/script.sh")
assertThat(scriptEntry.unixMode).isEqualTo(expectedExecutableMode)
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Goooler
force-pushed
the
g/20260809/stop-normalizing
branch
from
August 9, 2026 14:16
7a8bec9 to
040b005
Compare
Goooler
force-pushed
the
g/20260809/stop-normalizing
branch
from
August 9, 2026 14:19
040b005 to
ae7b42b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.