1+ load ("@rules_java//java:defs.bzl" , "java_library" )
12load ("@aspect_bazel_lib//lib:diff_test.bzl" , "diff_test" )
23load ("//:defs.bzl" , "artifact" , "java_export" )
34
@@ -234,6 +235,50 @@ diff_test(
234235 file2 = "pom-with-maven-defined-exclusions.golden.xml" ,
235236)
236237
238+ ####
239+ # Test for transitive dependency with maven.artifact() exclusions
240+ ####
241+
242+ # Scenario 1: java_export -> java_export -> guava (with exclusions)
243+ # The intermediate java_export should have guava with exclusions in ITS pom.
244+ # The top-level java_export should only have the intermediate library in its pom.
245+
246+ java_export (
247+ name = "intermediate-library-export" ,
248+ srcs = ["OtherLibrary.java" ],
249+ maven_coordinates = "com.example:intermediate:1.0.0" ,
250+ deps = [
251+ "@pom_exclusion_testing_coursier//:com_google_guava_guava" ,
252+ ],
253+ )
254+
255+ # Verify that the intermediate library's POM has guava WITH exclusions
256+ diff_test (
257+ name = "validate-intermediate-library-pom" ,
258+ file1 = ":intermediate-library-export-pom" ,
259+ file2 = "pom-intermediate-library.golden.xml" ,
260+ )
261+
262+ java_export (
263+ name = "pom-transitive-dep-with-exclusions" ,
264+ srcs = ["PomExample.java" ],
265+ maven_coordinates = "com.example:app:1.0.0" ,
266+ deps = [
267+ ":intermediate-library-export" ,
268+ ],
269+ )
270+
271+ # Verify that the top-level POM only has the intermediate library (not guava)
272+ diff_test (
273+ name = "validate-pom-transitive-dep-with-exclusions" ,
274+ file1 = ":pom-transitive-dep-with-exclusions-pom" ,
275+ file2 = "pom-transitive-dep-with-exclusions.golden.xml" ,
276+ )
277+
278+ # Scenario 2: java_export -> java_library (no maven_coordinates) -> guava
279+ # The java_library is bundled into the java_export, so guava becomes a
280+ # direct dependency of the java_export's POM (with exclusions).
281+
237282java_library (
238283 name = "other-library" ,
239284 srcs = ["OtherLibrary.java" ],
@@ -242,13 +287,18 @@ java_library(
242287 ],
243288)
244289
245- # This is to ensure that the guava dependency appears in the pom.xml with the correct exclusions,
246- # even though it is not directly on the java_export, it is on the java_library dep.
247290java_export (
248- name = "pom-transitive-exclusion " ,
291+ name = "pom-bundled-dep-with-exclusions " ,
249292 srcs = ["PomExample.java" ],
250293 maven_coordinates = "com.example:app:1.0.0" ,
251294 deps = [
252295 ":other-library" ,
253296 ],
254297)
298+
299+ # Verify that guava (with exclusions) appears in the POM since the helper is bundled
300+ diff_test (
301+ name = "validate-pom-bundled-dep-with-exclusions" ,
302+ file1 = ":pom-bundled-dep-with-exclusions-pom" ,
303+ file2 = "pom-with-maven-defined-exclusions.golden.xml" ,
304+ )
0 commit comments