Skip to content

Commit 444d7dd

Browse files
[MNG-8295] Add IT for Dependency Manager Transitivity (#384)
Co-authored-by: DidierLoiseau <didierloiseau+github@gmail.com>
1 parent 57dee65 commit 444d7dd

File tree

18 files changed

+523
-2
lines changed

18 files changed

+523
-2
lines changed

core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4720DependencyManagementExclusionMergeTest.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4720">MNG-4720</a>.
3030
*
3131
* @author Benjamin Bentmann
32+
* @author Ddiier Loiseau
3233
*/
3334
public class MavenITmng4720DependencyManagementExclusionMergeTest extends AbstractMavenIntegrationTestCase {
3435

@@ -39,11 +40,13 @@ public MavenITmng4720DependencyManagementExclusionMergeTest() {
3940
/**
4041
* Verify the effective exclusions applied during transitive dependency resolution when both the regular
4142
* dependency section and dependency management declare exclusions for a particular dependency.
43+
* <p>
44+
* By default, the dependency management of transitive dependencies is now taken into account.
4245
*
4346
* @throws Exception in case of failure
4447
*/
4548
@Test
46-
public void testit() throws Exception {
49+
public void testitWithTransitiveDependencyManager() throws Exception {
4750
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4720");
4851

4952
Verifier verifier = newVerifier(testDir.getAbsolutePath());
@@ -63,7 +66,45 @@ public void testit() throws Exception {
6366

6467
assertFalse(classpath.toString(), classpath.contains("b-0.1.jar"));
6568

66-
// should better have been excluded as well, now it's a matter of backward-compat
69+
// dependency management in a excludes d
70+
if (matchesVersionRange("[4.0.0-beta-5,)")) {
71+
assertFalse(classpath.toString(), classpath.contains("d-0.1.jar"));
72+
} else {
73+
assertTrue(classpath.toString(), classpath.contains("d-0.1.jar"));
74+
}
75+
}
76+
77+
/**
78+
* Verify the effective exclusions applied during transitive dependency resolution when both the regular
79+
* dependency section and dependency management declare exclusions for a particular dependency.
80+
* <p>
81+
* This tests the same behaviour with dependency manager transitivity disabled.
82+
*
83+
* @throws Exception in case of failure
84+
*/
85+
@Test
86+
public void testitWithTransitiveDependencyManagerDisabled() throws Exception {
87+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4720");
88+
89+
Verifier verifier = newVerifier(testDir.getAbsolutePath());
90+
verifier.setAutoclean(false);
91+
verifier.deleteArtifacts("org.apache.maven.its.mng4720");
92+
verifier.addCliArgument("-s");
93+
verifier.addCliArgument("settings.xml");
94+
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
95+
verifier.addCliArgument("-Dmaven.resolver.dependencyManagerTransitivity=false");
96+
verifier.addCliArgument("validate");
97+
verifier.execute();
98+
verifier.verifyErrorFreeLog();
99+
100+
List<String> classpath = verifier.loadLines("target/classpath.txt", "UTF-8");
101+
102+
assertTrue(classpath.toString(), classpath.contains("a-0.1.jar"));
103+
assertTrue(classpath.toString(), classpath.contains("c-0.1.jar"));
104+
105+
assertFalse(classpath.toString(), classpath.contains("b-0.1.jar"));
106+
107+
// backward-compat: dependency management is ignored except in root pom
67108
assertTrue(classpath.toString(), classpath.contains("d-0.1.jar"));
68109
}
69110
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.it;
20+
21+
import java.io.File;
22+
import java.util.List;
23+
24+
import org.apache.maven.shared.verifier.Verifier;
25+
import org.apache.maven.shared.verifier.util.ResourceExtractor;
26+
import org.junit.jupiter.api.Test;
27+
28+
/**
29+
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-7982">MNG-7982</a>.
30+
*
31+
* @author Didier Loiseau
32+
*/
33+
public class MavenITmng7982DependencyManagementTransitivityTest extends AbstractMavenIntegrationTestCase {
34+
35+
public MavenITmng7982DependencyManagementTransitivityTest() {
36+
super("[4.0.0-beta-5,)");
37+
}
38+
39+
/**
40+
* Verify the effective dependency versions determined when using the transitive dependency management (default).
41+
* <p>
42+
* By default, the dependency management of transitive dependencies should be taken into account.
43+
*
44+
* @throws Exception in case of failure
45+
*/
46+
@Test
47+
public void testitWithTransitiveDependencyManager() throws Exception {
48+
File testDir =
49+
ResourceExtractor.simpleExtractResources(getClass(), "/mng-7982-transitive-dependency-management");
50+
51+
Verifier verifier = newVerifier(testDir.getAbsolutePath());
52+
verifier.deleteArtifacts("org.apache.maven.its.mng7982");
53+
verifier.addCliArgument("-s");
54+
verifier.addCliArgument("settings.xml");
55+
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
56+
verifier.addCliArgument("verify");
57+
verifier.execute();
58+
verifier.verifyErrorFreeLog();
59+
60+
List<String> bClasspath = verifier.loadLines("b/target/classpath.txt", "UTF-8");
61+
assertTrue(bClasspath.toString(), bClasspath.contains("a-1.jar"));
62+
assertFalse(bClasspath.toString(), bClasspath.contains("a-2.jar"));
63+
64+
List<String> cClasspath = verifier.loadLines("c/target/classpath.txt", "UTF-8");
65+
assertTrue(cClasspath.toString(), cClasspath.contains("b-1.jar"));
66+
assertFalse(cClasspath.toString(), cClasspath.contains("a-1.jar"));
67+
assertTrue(cClasspath.toString(), cClasspath.contains("a-2.jar"));
68+
69+
List<String> dClasspath = verifier.loadLines("d/target/classpath.txt", "UTF-8");
70+
assertTrue(dClasspath.toString(), dClasspath.contains("c-1.jar"));
71+
assertTrue(dClasspath.toString(), dClasspath.contains("b-1.jar"));
72+
assertFalse(dClasspath.toString(), dClasspath.contains("a-1.jar"));
73+
assertTrue(dClasspath.toString(), dClasspath.contains("a-2.jar"));
74+
75+
List<String> eClasspath = verifier.loadLines("e/target/classpath.txt", "UTF-8");
76+
assertTrue(eClasspath.toString(), eClasspath.contains("d-1.jar"));
77+
assertTrue(eClasspath.toString(), eClasspath.contains("c-1.jar"));
78+
assertTrue(eClasspath.toString(), eClasspath.contains("b-1.jar"));
79+
assertFalse(eClasspath.toString(), eClasspath.contains("a-1.jar"));
80+
assertTrue(eClasspath.toString(), eClasspath.contains("a-2.jar"));
81+
}
82+
83+
/**
84+
* Verify the effective dependency versions determined when disabling the transitive dependency management (Maven 2/3 behavior).
85+
* <p>
86+
* When transitivity is disabled, the dependency management of transitive dependencies should is ignored.
87+
*
88+
* @throws Exception in case of failure
89+
*/
90+
@Test
91+
public void testitWithTransitiveDependencyManagerDisabled() throws Exception {
92+
File testDir =
93+
ResourceExtractor.simpleExtractResources(getClass(), "/mng-7982-transitive-dependency-management");
94+
95+
Verifier verifier = newVerifier(testDir.getAbsolutePath());
96+
verifier.deleteArtifacts("org.apache.maven.its.mng7982");
97+
verifier.addCliArgument("-s");
98+
verifier.addCliArgument("settings.xml");
99+
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
100+
verifier.addCliArgument("verify");
101+
verifier.addCliArgument("-Dmaven.resolver.dependencyManagerTransitivity=false");
102+
verifier.execute();
103+
verifier.verifyErrorFreeLog();
104+
105+
List<String> bClasspath = verifier.loadLines("b/target/classpath.txt", "UTF-8");
106+
assertTrue(bClasspath.toString(), bClasspath.contains("a-1.jar"));
107+
assertFalse(bClasspath.toString(), bClasspath.contains("a-2.jar"));
108+
109+
List<String> cClasspath = verifier.loadLines("c/target/classpath.txt", "UTF-8");
110+
assertTrue(cClasspath.toString(), cClasspath.contains("b-1.jar"));
111+
assertFalse(cClasspath.toString(), cClasspath.contains("a-1.jar"));
112+
assertTrue(cClasspath.toString(), cClasspath.contains("a-2.jar"));
113+
114+
List<String> dClasspath = verifier.loadLines("d/target/classpath.txt", "UTF-8");
115+
assertTrue(dClasspath.toString(), dClasspath.contains("c-1.jar"));
116+
assertTrue(dClasspath.toString(), dClasspath.contains("b-1.jar"));
117+
// dependency management of c is ignored
118+
assertTrue(dClasspath.toString(), dClasspath.contains("a-1.jar"));
119+
assertFalse(dClasspath.toString(), dClasspath.contains("a-2.jar"));
120+
121+
List<String> eClasspath = verifier.loadLines("e/target/classpath.txt", "UTF-8");
122+
assertTrue(eClasspath.toString(), eClasspath.contains("d-1.jar"));
123+
assertTrue(eClasspath.toString(), eClasspath.contains("c-1.jar"));
124+
assertTrue(eClasspath.toString(), eClasspath.contains("b-1.jar"));
125+
// dependency management of c is ignored
126+
assertTrue(dClasspath.toString(), dClasspath.contains("a-1.jar"));
127+
assertFalse(dClasspath.toString(), dClasspath.contains("a-2.jar"));
128+
}
129+
}

core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public TestSuiteOrdering() {
120120
* the tests are to finishing. Newer tests are also more likely to fail, so this is
121121
* a fail fast technique as well.
122122
*/
123+
suite.addTestSuite(MavenITmng7982DependencyManagementTransitivityTest.class);
123124
suite.addTestSuite(MavenITmng8294ParentChecksTest.class);
124125
suite.addTestSuite(MavenITmng8293BomImportFromReactor.class);
125126
suite.addTestSuite(MavenITmng8288NoRootPomTest.class);

core-it-suite/src/test/resources-filtered/bootstrap.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#4 mv bootstrap.txt tmp.txt && cat tmp.txt | sort -u > bootstrap.txt && rm tmp.txt
66
#5
77
com.google.code.findbugs:jsr305:1.3.9
8+
com.google.errorprone:error_prone_annotations:2.16
9+
com.google.errorprone:error_prone_annotations:2.19.1
810
com.google.guava:guava:10.0.1
911
com.google.guava:guava:16.0.1
1012
com.thoughtworks.qdox:qdox:2.0-M9
@@ -96,6 +98,7 @@ org.apache.maven.plugins:maven-ear-plugin:${stubPluginVersion}
9698
org.apache.maven.plugins:maven-ear-plugin:3.2.0
9799
org.apache.maven.plugins:maven-ejb-plugin:${stubPluginVersion}
98100
org.apache.maven.plugins:maven-ejb-plugin:3.1.0
101+
org.apache.maven.plugins:maven-enforcer-plugin:3.0.0
99102
org.apache.maven.plugins:maven-help-plugin:3.3.0
100103
org.apache.maven.plugins:maven-install-plugin:${stubPluginVersion}
101104
org.apache.maven.plugins:maven-install-plugin:3.0.1
@@ -110,6 +113,7 @@ org.apache.maven.plugins:maven-plugin-plugin:3.6.0
110113
org.apache.maven.plugins:maven-plugin-plugin:3.9.0
111114
org.apache.maven.plugins:maven-rar-plugin:${stubPluginVersion}
112115
org.apache.maven.plugins:maven-release-plugin:3.0.0-M5
116+
org.apache.maven.plugins:maven-remote-resources-plugin:1.7.0
113117
org.apache.maven.plugins:maven-resources-plugin:${stubPluginVersion}
114118
org.apache.maven.plugins:maven-resources-plugin:3.2.0
115119
org.apache.maven.plugins:maven-resources-plugin:3.3.0
@@ -151,6 +155,8 @@ org.apache.maven:maven-script-ant:2.1.0
151155
org.apache.maven:maven-settings-builder:3.1.1
152156
org.apache.maven:maven-settings:3.1.1
153157
org.apache.maven.plugin-testing:maven-plugin-testing-harness:3.3.0
158+
org.checkerframework:checker-qual:3.21.2
159+
org.checkerframework:checker-qual:3.35.0
154160
org.codehaus.gmavenplus:gmavenplus-plugin:1.11.0
155161
org.codehaus.modello:modello-maven-plugin:2.1.1
156162
org.codehaus.mojo:build-helper-maven-plugin:3.2.0
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project>
21+
<modelVersion>4.1.0</modelVersion>
22+
23+
<parent />
24+
25+
<groupId>org.apache.maven.its.mng7982</groupId>
26+
<artifactId>b</artifactId>
27+
<version>1</version>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.apache.maven.its.mng7982</groupId>
32+
<artifactId>a</artifactId>
33+
<version>1</version>
34+
</dependency>
35+
</dependencies>
36+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project>
21+
<modelVersion>4.1.0</modelVersion>
22+
23+
<parent />
24+
25+
<groupId>org.apache.maven.its.mng7982</groupId>
26+
<artifactId>c</artifactId>
27+
<version>1</version>
28+
29+
<dependencyManagement>
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.apache.maven.its.mng7982</groupId>
33+
<artifactId>a</artifactId>
34+
<version>2</version>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.apache.maven.its.mng7982</groupId>
41+
<artifactId>b</artifactId>
42+
<version>1</version>
43+
</dependency>
44+
</dependencies>
45+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project>
21+
<modelVersion>4.1.0</modelVersion>
22+
23+
<parent />
24+
25+
<groupId>org.apache.maven.its.mng7982</groupId>
26+
<artifactId>d</artifactId>
27+
<version>1</version>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.apache.maven.its.mng7982</groupId>
32+
<artifactId>c</artifactId>
33+
<version>1</version>
34+
</dependency>
35+
</dependencies>
36+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project>
21+
<modelVersion>4.1.0</modelVersion>
22+
23+
<parent />
24+
25+
<groupId>org.apache.maven.its.mng7982</groupId>
26+
<artifactId>e</artifactId>
27+
<version>1</version>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.apache.maven.its.mng7982</groupId>
32+
<artifactId>d</artifactId>
33+
<version>1</version>
34+
</dependency>
35+
</dependencies>
36+
</project>

0 commit comments

Comments
 (0)