@@ -261,26 +261,36 @@ def _find_duplicate_artifacts_across_submodules(non_root_artifacts, root_maven_m
261
261
return duplicates
262
262
263
263
def _deduplicate_artifacts_with_root_priority (name , root_artifacts , non_root_artifacts ):
264
- """Deduplicate artifacts, giving priority to root module artifacts."""
264
+ """Deduplicate artifacts, giving priority to root module artifacts with force_version set ."""
265
265
266
- # Collect maven modules from root artifacts (handle mixed types)
267
- root_maven_modules = []
266
+ # Collect maven modules from root artifacts that have force_version = True
267
+ root_maven_modules_with_force_version = []
268
+ for artifact in root_artifacts :
269
+ if getattr (artifact , "force_version" , False ):
270
+ maven_module = _get_maven_module (artifact )
271
+ if maven_module not in root_maven_modules_with_force_version :
272
+ root_maven_modules_with_force_version .append (maven_module )
273
+
274
+ # Collect all maven modules from root artifacts (for duplicate detection)
275
+ all_root_maven_modules = []
268
276
for artifact in root_artifacts :
269
277
maven_module = _get_maven_module (artifact )
270
- if maven_module not in root_maven_modules :
271
- root_maven_modules .append (maven_module )
278
+ if maven_module not in all_root_maven_modules :
279
+ all_root_maven_modules .append (maven_module )
272
280
273
281
# Find duplicates across sub-modules that aren't overridden by root
274
282
duplicate_submodule_artifacts = _find_duplicate_artifacts_across_submodules (
275
283
non_root_artifacts ,
276
- root_maven_modules ,
284
+ all_root_maven_modules ,
277
285
)
278
286
279
- # Filter non-root artifacts that conflict with root artifacts
287
+ # Filter non-root artifacts that conflict with root artifacts that have force_version = True
280
288
filtered_non_root = []
281
289
for artifact in non_root_artifacts :
282
290
maven_module = _get_maven_module (artifact )
283
- if not maven_module in root_maven_modules :
291
+
292
+ # Only exclude if root module has force_version = True for this coordinate
293
+ if not maven_module in root_maven_modules_with_force_version :
284
294
filtered_non_root .append (artifact )
285
295
286
296
# Log detailed warning for duplicate sub-module artifacts
@@ -293,7 +303,7 @@ def _deduplicate_artifacts_with_root_priority(name, root_artifacts, non_root_art
293
303
warning_parts .append (maven_module )
294
304
295
305
print ("WARNING: The following coordinates from `%s` appear in multiple sub-modules with potentially different versions. " % name +
296
- "Consider adding one of these to your root module to ensure consistent versions:\n \t %s" %
306
+ "Consider adding one of these to your root module to ensure consistent versions and setting `force_version = True` on that artifact :\n \t %s" %
297
307
"\n \t " .join (sorted (warning_parts )))
298
308
299
309
return root_artifacts + filtered_non_root
0 commit comments