Skip to content

Commit 9335ec8

Browse files
committed
Improve consistency by prefering bazel_dep over Go
Letting the bazel_dep and Go dependency participate equally in the version resolution is creating various inconsistencies. This can lead to to a root module having to either use `inject_repo` or `use_repo` and `override_repo`. Resolve this by consistently preferring the `bazel_dep` over the Go dependency. Keep the existing code that warns (or can fail) if the dependencies are at different versions. Example MODULE.bazel: ``` module( name = "bazel_dep_should_win", ) bazel_dep(name = "rules_go", version = "0.53.0") bazel_dep(name = "gazelle", version = "0.42.0") bazel_dep(name = "circl", version = "1.3.8") go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//:go.mod") ``` And the go.mod referring to a newer version. Fixes #2060
1 parent da58629 commit 9335ec8

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

internal/bzlmod/go_deps.bzl

+2-7
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,8 @@ def _go_deps_impl(module_ctx):
566566

567567
bazel_dep_is_older = path in module_resolutions and bazel_dep.version < module_resolutions[path].version
568568

569-
# Version mismatches between the Go module and the bazel_dep can confuse Go tooling. If the bazel_dep version
570-
# is lower, it won't be used, which can result in unexpected builds and should thus always be reported, even for
571-
# indirect deps. Explicitly overridden modules are not reported as this requires manual action.
569+
# Version mismatches between the Go module and the bazel_dep are problematic. For consistency always
570+
# prefer the bazel_dep version and report any mismatch to the user.
572571
if (path in module_resolutions and
573572
bazel_dep.version != module_resolutions[path].version and
574573
bazel_dep.version != _HIGHEST_VERSION_SENTINEL and
@@ -620,10 +619,6 @@ Mismatch between versions requested for Go module {module}:
620619
go_module_version = go_module_version,
621620
), *remediation)
622621

623-
# Only use the Bazel module if it is at least as high as the required Go module version.
624-
if bazel_dep_is_older:
625-
continue
626-
627622
# TODO: We should update root_versions if the bazel_dep is a direct dependency of the root
628623
# module. However, we currently don't have a way to determine that.
629624
module_resolutions[path] = bazel_dep

0 commit comments

Comments
 (0)