fix: disambiguate duplicate dependency JARs by content hash instead of file size - #4528
Open
sideeffffect wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…f file size When multiple dependency JARs share the same filename, jib renames the duplicates by appending a suffix so they don't overwrite each other in the image. Until now that suffix was the file size (Files.size), which is not a reliable discriminator: two genuinely different JARs that happen to share a filename can also happen to have the exact same size, in which case one still silently overwrites the other, leading to NoClassDefFoundError at runtime. Use a short prefix of the SHA-256 of the JAR contents instead, computed via jib-core's existing Digests utility. A content hash distinguishes distinct JARs regardless of size, while remaining deterministic across builds. The digest is truncated to 12 hex chars to keep filenames reasonable. The two call sites (JavaContainerBuilder and PluginConfigurationProcessor, which must stay in sync) are both updated, along with the affected tests and the jib-core / jib-maven-plugin / jib-gradle-plugin changelogs. See GoogleContainerTools#3331
sideeffffect
force-pushed
the
dependency-jar-dedup-content-hash
branch
from
September 1, 2026 21:18
3bfd8d0 to
5a36e09
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.
Issue
When several dependency JARs share the same filename, jib renames the duplicates so they don't overwrite each other under
libs/in the image. Today the disambiguating suffix is the file size (Files.size(...)):File size is not a reliable discriminator. Two genuinely different JARs that happen to share a filename can also happen to have the exact same size, in which case one still silently overwrites the other — producing
NoClassDefFoundErrorat runtime. This is the same class of problem originally reported in #3331; the size-based fix narrowed it but didn't close it.Fix
Use a short prefix of the SHA-256 of the JAR contents as the suffix instead, computed via jib-core's existing
Digestsutility. A content hash distinguishes distinct JARs regardless of their size, while staying deterministic across builds (so it doesn't hurt reproducibility or layer caching). The digest is truncated to 12 hex characters to keep filenames reasonable — more than enough to tell apart the handful of same-named JARs in a single build.The renaming exists in two places that are required to stay in sync:
jib-core—JavaContainerBuilderjib-plugins-common—PluginConfigurationProcessor(used by both the Maven and Gradle plugins)Both are updated identically, via a small private
computeContentHash(Path)helper in each.Tests
Updated the two existing duplicate-JAR tests to assert the new content-hash suffixes (
JavaContainerBuilderTest,PluginConfigurationProcessorTest). Verified locally::jib-core:test --tests JavaContainerBuilderTest✅:jib-plugins-common:test --tests PluginConfigurationProcessorTest✅verifyGoogleJavaFormatand errorprone/NullAway (viacompileJava) ✅CHANGELOGs updated for
jib-core,jib-maven-plugin, andjib-gradle-plugin.Fixes the remaining collision described in #3331.