Skip to content

bzlmod: enforce root artifact precedence when version_conflict_policy…#1556

Open
davido wants to merge 1 commit into
bazel-contrib:masterfrom
davido:issue_1549
Open

bzlmod: enforce root artifact precedence when version_conflict_policy…#1556
davido wants to merge 1 commit into
bazel-contrib:masterfrom
davido:issue_1549

Conversation

@davido

@davido davido commented Mar 4, 2026

Copy link
Copy Markdown

…="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.

@davido
davido requested review from cheister, jin and shs96c as code owners March 4, 2026 08:25
…="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.
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.

1 participant