bzlmod: enforce root artifact precedence when version_conflict_policy…#1556
Open
davido wants to merge 1 commit into
Open
bzlmod: enforce root artifact precedence when version_conflict_policy…#1556davido wants to merge 1 commit into
davido wants to merge 1 commit into
Conversation
…="pinned" Addresses bazel-contrib#1549. When using rules_jvm_external with bzlmod module layering, multiple modules can contribute artifacts into the same maven.install repository via known_contributing_modules. If both the root module and a contributing module declare the same group:artifact with different versions, the current merge logic may retain both versions unless the root explicitly sets force_version = True for each artifact (for example using maven.amend_artifact). This results in duplicate artifact entries in the merged artifact list and causes resolution to fail early with "Found duplicate artifact versions", even when the root module sets version_conflict_policy = "pinned". However, the documented semantics of "pinned" are that user-specified versions should be chosen unconditionally over transitive ones. This change aligns layered resolution with that expectation by treating all artifacts declared by the root module as if force_version = True when version_conflict_policy = "pinned" is used. This ensures that root-declared versions take precedence during layered dependency merging and prevents duplicate coordinates from reaching the resolver. As a result, root modules can enforce their dependency versions across layered module contributions without needing to enumerate each artifact with maven.amend_artifact(force_version = ...). This is particularly useful for applications acting as the root module that depend on libraries contributing their own Maven dependencies via bzlmod layering, and that require deterministic control over dependency versions across the combined dependency graph.
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.
…="pinned"
Addresses #1549.
When using rules_jvm_external with bzlmod module layering, multiple modules can contribute artifacts into the same maven.install repository via known_contributing_modules.
If both the root module and a contributing module declare the same group:artifact with different versions, the current merge logic may retain both versions unless the root explicitly sets force_version = True for each artifact (for example using maven.amend_artifact). This results in duplicate artifact entries in the merged artifact list and causes resolution to fail early with "Found duplicate artifact versions", even when the root module sets version_conflict_policy = "pinned".
However, the documented semantics of "pinned" are that user-specified versions should be chosen unconditionally over transitive ones.
This change aligns layered resolution with that expectation by treating all artifacts declared by the root module as if force_version = True when version_conflict_policy = "pinned" is used. This ensures that root-declared versions take precedence during layered dependency merging and prevents duplicate coordinates from reaching the resolver.
As a result, root modules can enforce their dependency versions across layered module contributions without needing to enumerate each artifact with maven.amend_artifact(force_version = ...).
This is particularly useful for applications acting as the root module that depend on libraries contributing their own Maven dependencies via bzlmod layering, and that require deterministic control over dependency versions across the combined dependency graph.