Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add dependencyManagement exclusions to the child exclusions #6969

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions pkg/dependency/parser/java/pom/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,60 @@ func TestPom_Parse(t *testing.T) {
},
},
},
// ➜ mvn dependency:tree
// ...
// [INFO]
// [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ child ---
// [INFO] com.example:child:jar:3.0.0
// [INFO] \- org.example:example-exclusions:jar:3.0.0:compile
// [INFO] \- org.example:example-nested:jar:3.3.3:compile
// [INFO] ------------------------------------------------------------------------
{
name: "exclusions in child and parent dependency management",
inputFile: filepath.Join("testdata", "exclusions-parent-dependency-management", "child", "pom.xml"),
local: true,
want: []ftypes.Package{
{
ID: "com.example:child:3.0.0",
Name: "com.example:child",
Version: "3.0.0",
Licenses: []string{"Apache 2.0"},
Relationship: ftypes.RelationshipRoot,
},
{
ID: "org.example:example-exclusions:3.0.0",
Name: "org.example:example-exclusions",
Version: "3.0.0",
Relationship: ftypes.RelationshipDirect,
Locations: ftypes.Locations{
{
StartLine: 26,
EndLine: 35,
},
},
},
{
ID: "org.example:example-nested:3.3.3",
Name: "org.example:example-nested",
Version: "3.3.3",
Relationship: ftypes.RelationshipIndirect,
},
},
wantDeps: []ftypes.Dependency{
{
ID: "com.example:child:3.0.0",
DependsOn: []string{
"org.example:example-exclusions:3.0.0",
},
},
{
ID: "org.example:example-exclusions:3.0.0",
DependsOn: []string{
"org.example:example-nested:3.3.3",
},
},
},
},
{
name: "exclusions with wildcards",
inputFile: filepath.Join("testdata", "wildcard-exclusions", "pom.xml"),
Expand Down
5 changes: 2 additions & 3 deletions pkg/dependency/parser/java/pom/pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ func (d pomDependency) Resolve(props map[string]string, depManagement, rootDepMa
if !dep.Optional {
dep.Optional = managed.Optional
}
if len(dep.Exclusions.Exclusion) == 0 {
dep.Exclusions = managed.Exclusions
}
// `mvn` always merges exceptions for pom and parent
dep.Exclusions.Exclusion = append(dep.Exclusions.Exclusion, managed.Exclusions.Exclusion...)
}
return dep
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>child</artifactId>
<version>3.0.0</version>

<name>child</name>
<description>Child</description>

<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>2.0.0</version>
</parent>

<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-exclusions</artifactId>
<exclusions>
<exclusion>
<groupId>org.example</groupId>
<artifactId>example-dependency</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>2.0.0</version>

<packaging>pom</packaging>
<name>parent</name>
<description>Parent</description>

<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-exclusions</artifactId>
<version>3.0.0</version>
<exclusions>
<exclusion>
<groupId>org.example</groupId>
<artifactId>example-dependency2</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>example-exclusions</artifactId>
<version>3.0.0</version>

<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-dependency</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-dependency2</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-nested</artifactId>
<version>3.3.3</version>
</dependency>
</dependencies>

</project>