Skip to content

Commit 82d27b2

Browse files
committed
cherry-pick vinnybod/fix-issue-1498
1 parent 443e0b3 commit 82d27b2

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed

private/rules/maven_utils.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ def generate_pom(
101101
"{classifier}": unpacked_coordinates.classifier or "jar",
102102
}
103103

104-
for key in exclusions:
105-
if key not in versioned_dep_coordinates and key not in unversioned_dep_coordinates:
106-
fail("Key %s in exclusions does not occur in versioned_dep_coordinates or unversioned_dep_coordinates" % key)
107-
108104
if parent:
109105
# We only want the groupId, artifactID, and version
110106
unpacked_parent = _unpack_coordinates(parent)

tests/integration/pom_file/BUILD

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
12
load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
23
load("//: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+
237282
java_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.
247290
java_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+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>intermediate</artifactId>
8+
<version>1.0.0</version>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.google.guava</groupId>
13+
<artifactId>guava</artifactId>
14+
<version>31.1-jre</version>
15+
<scope>runtime</scope>
16+
<exclusions>
17+
<exclusion>
18+
<groupId>com.google.errorprone</groupId>
19+
<artifactId>error_prone_annotations</artifactId>
20+
</exclusion>
21+
</exclusions>
22+
</dependency>
23+
</dependencies>
24+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>app</artifactId>
8+
<version>1.0.0</version>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.example</groupId>
13+
<artifactId>intermediate</artifactId>
14+
<version>1.0.0</version>
15+
<scope>runtime</scope>
16+
</dependency>
17+
</dependencies>
18+
</project>

0 commit comments

Comments
 (0)