@@ -145,18 +145,18 @@ def _add_exclusions(exclusions):
145
145
to_return .append (exclusion )
146
146
return to_return
147
147
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.
148
154
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 :
152
157
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
160
160
161
161
def _to_maven_coords (artifact ):
162
162
coords = "%s:%s" % (artifact .get ("group" ), artifact .get ("artifact" ))
@@ -223,8 +223,10 @@ def maven_impl(mctx):
223
223
# - ignore_empty_files: Treat jars that are empty as if they were not found.
224
224
# - additional_coursier_options: Additional options that will be passed to coursier.
225
225
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.)
228
230
repo_name_2_module_name = {}
229
231
230
232
for mod in mctx .modules :
@@ -344,6 +346,13 @@ def maven_impl(mctx):
344
346
345
347
repos [install .name ] = repo
346
348
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
+
347
356
# Breaking out the logic for picking lock files, because it's not terribly simple
348
357
repo_to_lock_file = {}
349
358
for mod in mctx .modules :
0 commit comments