Skip to content

Commit 8c1aa26

Browse files
committed
fix: Add dependencyManagement exclusions to the child exclusions
1 parent e493fc9 commit 8c1aa26

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

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

+40
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,46 @@ func TestPom_Parse(t *testing.T) {
979979
},
980980
},
981981
},
982+
{
983+
name: "exclusions in child and parent dependency management",
984+
inputFile: filepath.Join("testdata", "exclusions-parent-dependency-management", "child", "pom.xml"),
985+
local: true,
986+
want: []ftypes.Package{
987+
{
988+
ID: "com.example:child:3.0.0",
989+
Name: "com.example:child",
990+
Version: "3.0.0",
991+
Licenses: []string{"Apache 2.0"},
992+
Relationship: ftypes.RelationshipRoot,
993+
},
994+
{
995+
ID: "org.example:example-nested:3.3.3",
996+
Name: "org.example:example-nested",
997+
Version: "3.3.3",
998+
Relationship: ftypes.RelationshipDirect,
999+
},
1000+
{
1001+
ID: "org.example:example-dependency:1.2.3",
1002+
Name: "org.example:example-dependency",
1003+
Version: "1.2.3",
1004+
Relationship: ftypes.RelationshipIndirect,
1005+
},
1006+
},
1007+
wantDeps: []ftypes.Dependency{
1008+
{
1009+
ID: "com.example:child:3.0.0",
1010+
DependsOn: []string{
1011+
"org.example:example-nested:3.3.3",
1012+
},
1013+
},
1014+
{
1015+
ID: "org.example:example-nested:3.3.3",
1016+
DependsOn: []string{
1017+
"org.example:example-dependency:1.2.3",
1018+
},
1019+
},
1020+
},
1021+
},
9821022
{
9831023
name: "exclusions with wildcards",
9841024
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-nested</artifactId>
29+
<exclusions>
30+
<exclusion>
31+
<groupId>org.example</groupId>
32+
<artifactId>example-api-common</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-nested</artifactId>
26+
<version>3.3.3</version>
27+
<exclusions>
28+
<exclusion>
29+
<groupId>org.example</groupId>
30+
<artifactId>example-api</artifactId>
31+
</exclusion>
32+
</exclusions>
33+
</dependency>
34+
</dependencies>
35+
</dependencyManagement>
36+
37+
</project>

0 commit comments

Comments
 (0)