Skip to content

Commit dc68a66

Browse files
fix: Add dependencyManagement exclusions to the child exclusions (#6969)
Co-authored-by: DmitriyLewen <[email protected]>
1 parent ec3e0ca commit dc68a66

File tree

5 files changed

+158
-3
lines changed

5 files changed

+158
-3
lines changed

pkg/dependency/parser/java/pom/parse_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,60 @@ func TestPom_Parse(t *testing.T) {
979979
},
980980
},
981981
},
982+
// ➜ mvn dependency:tree
983+
// ...
984+
// [INFO]
985+
// [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ child ---
986+
// [INFO] com.example:child:jar:3.0.0
987+
// [INFO] \- org.example:example-exclusions:jar:3.0.0:compile
988+
// [INFO] \- org.example:example-nested:jar:3.3.3:compile
989+
// [INFO] ------------------------------------------------------------------------
990+
{
991+
name: "exclusions in child and parent dependency management",
992+
inputFile: filepath.Join("testdata", "exclusions-parent-dependency-management", "child", "pom.xml"),
993+
local: true,
994+
want: []ftypes.Package{
995+
{
996+
ID: "com.example:child:3.0.0",
997+
Name: "com.example:child",
998+
Version: "3.0.0",
999+
Licenses: []string{"Apache 2.0"},
1000+
Relationship: ftypes.RelationshipRoot,
1001+
},
1002+
{
1003+
ID: "org.example:example-exclusions:3.0.0",
1004+
Name: "org.example:example-exclusions",
1005+
Version: "3.0.0",
1006+
Relationship: ftypes.RelationshipDirect,
1007+
Locations: ftypes.Locations{
1008+
{
1009+
StartLine: 26,
1010+
EndLine: 35,
1011+
},
1012+
},
1013+
},
1014+
{
1015+
ID: "org.example:example-nested:3.3.3",
1016+
Name: "org.example:example-nested",
1017+
Version: "3.3.3",
1018+
Relationship: ftypes.RelationshipIndirect,
1019+
},
1020+
},
1021+
wantDeps: []ftypes.Dependency{
1022+
{
1023+
ID: "com.example:child:3.0.0",
1024+
DependsOn: []string{
1025+
"org.example:example-exclusions:3.0.0",
1026+
},
1027+
},
1028+
{
1029+
ID: "org.example:example-exclusions:3.0.0",
1030+
DependsOn: []string{
1031+
"org.example:example-nested:3.3.3",
1032+
},
1033+
},
1034+
},
1035+
},
9821036
{
9831037
name: "exclusions with wildcards",
9841038
inputFile: filepath.Join("testdata", "wildcard-exclusions", "pom.xml"),

pkg/dependency/parser/java/pom/pom.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ func (d pomDependency) Resolve(props map[string]string, depManagement, rootDepMa
266266
if !dep.Optional {
267267
dep.Optional = managed.Optional
268268
}
269-
if len(dep.Exclusions.Exclusion) == 0 {
270-
dep.Exclusions = managed.Exclusions
271-
}
269+
// `mvn` always merges exceptions for pom and parent
270+
dep.Exclusions.Exclusion = append(dep.Exclusions.Exclusion, managed.Exclusions.Exclusion...)
272271
}
273272
return dep
274273
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<artifactId>child</artifactId>
6+
<version>3.0.0</version>
7+
8+
<name>child</name>
9+
<description>Child</description>
10+
11+
<parent>
12+
<groupId>com.example</groupId>
13+
<artifactId>parent</artifactId>
14+
<version>2.0.0</version>
15+
</parent>
16+
17+
<licenses>
18+
<license>
19+
<name>Apache 2.0</name>
20+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
21+
<distribution>repo</distribution>
22+
</license>
23+
</licenses>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.example</groupId>
28+
<artifactId>example-exclusions</artifactId>
29+
<exclusions>
30+
<exclusion>
31+
<groupId>org.example</groupId>
32+
<artifactId>example-dependency</artifactId>
33+
</exclusion>
34+
</exclusions>
35+
</dependency>
36+
</dependencies>
37+
38+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.example</groupId>
6+
<artifactId>parent</artifactId>
7+
<version>2.0.0</version>
8+
9+
<packaging>pom</packaging>
10+
<name>parent</name>
11+
<description>Parent</description>
12+
13+
<licenses>
14+
<license>
15+
<name>Apache 2.0</name>
16+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
17+
<distribution>repo</distribution>
18+
</license>
19+
</licenses>
20+
21+
<dependencyManagement>
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.example</groupId>
25+
<artifactId>example-exclusions</artifactId>
26+
<version>3.0.0</version>
27+
<exclusions>
28+
<exclusion>
29+
<groupId>org.example</groupId>
30+
<artifactId>example-dependency2</artifactId>
31+
</exclusion>
32+
</exclusions>
33+
</dependency>
34+
</dependencies>
35+
</dependencyManagement>
36+
37+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.example</groupId>
6+
<artifactId>example-exclusions</artifactId>
7+
<version>3.0.0</version>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>org.example</groupId>
12+
<artifactId>example-dependency</artifactId>
13+
<version>1.2.3</version>
14+
</dependency>
15+
<dependency>
16+
<groupId>org.example</groupId>
17+
<artifactId>example-dependency2</artifactId>
18+
<version>2.3.4</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.example</groupId>
22+
<artifactId>example-nested</artifactId>
23+
<version>3.3.3</version>
24+
</dependency>
25+
</dependencies>
26+
27+
</project>

0 commit comments

Comments
 (0)