Skip to content

Commit 083851c

Browse files
committed
Make multiple modules contributing to the same maven repo namespace warning less verbose and duplicated
1 parent 534e62d commit 083851c

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

private/extensions/maven.bzl

+21-12
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,18 @@ def _add_exclusions(exclusions):
145145
to_return.append(exclusion)
146146
return to_return
147147

148+
# Each bzlmod module may contribute jars to different rules_jvm_external maven repo namespaces.
149+
# We record this mapping of repo_name to the list of modules that contributed to it, and emit a warning
150+
# to the user if there are more than one module that contributed to the same repo name.
151+
#
152+
# This can be typical for the default @maven namespace, if a bzlmod dependency
153+
# wishes to contribute to the users' jars.
148154
def _check_repo_name(repo_name_2_module_name, repo_name, module_name):
149-
known_name = repo_name_2_module_name.get(repo_name)
150-
if known_name == None:
151-
repo_name_2_module_name[repo_name] = module_name
155+
known_names = repo_name_2_module_name.get(repo_name, [])
156+
if module_name in known_names:
152157
return
153-
154-
if module_name != known_name:
155-
print("The maven repository '%s' is used in two different bazel modules, originally in '%s' and now in '%s'" % (
156-
repo_name,
157-
known_name,
158-
module_name,
159-
))
158+
known_names.append(module_name)
159+
repo_name_2_module_name[repo_name] = known_names
160160

161161
def _to_maven_coords(artifact):
162162
coords = "%s:%s" % (artifact.get("group"), artifact.get("artifact"))
@@ -223,8 +223,10 @@ def maven_impl(mctx):
223223
# - ignore_empty_files: Treat jars that are empty as if they were not found.
224224
# - additional_coursier_options: Additional options that will be passed to coursier.
225225

226-
# Mapping of `name`s to `bazel_module.name` This will allow us to warn users when more than
227-
# module attempts to update a maven repo (which is normally undesired behaviour)
226+
# Mapping of `name`s to a list of `bazel_module.name`. This will allow us to
227+
# warn users when more than one module attempts to update a maven repo
228+
# (which is normally undesired behaviour, but supported as multiple modules
229+
# can intentionally contribute to the default `maven` repo namespace.)
228230
repo_name_2_module_name = {}
229231

230232
for mod in mctx.modules:
@@ -344,6 +346,13 @@ def maven_impl(mctx):
344346

345347
repos[install.name] = repo
346348

349+
for (repo_name, known_names) in repo_name_2_module_name.items():
350+
if len(known_names) > 1:
351+
print("The maven repository '%s' is used in multiple bzlmod modules: %s" % (
352+
repo_name, # e.g. "maven"
353+
str(known_names), # e.g. bzl_module_foo, bzl_module_bar
354+
))
355+
347356
# Breaking out the logic for picking lock files, because it's not terribly simple
348357
repo_to_lock_file = {}
349358
for mod in mctx.modules:

0 commit comments

Comments
 (0)