[MNG-8295] Add IT for Dependency Manager Transitivity (#384)

Co-authored-by: DidierLoiseau <didierloiseau+github@gmail.com>
This commit is contained in:
Guillaume Nodet 2024-10-15 14:25:54 +02:00 committed by GitHub
parent 83f034d177
commit d98fe8e9f0
18 changed files with 523 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test;
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4720">MNG-4720</a>.
*
* @author Benjamin Bentmann
* @author Ddiier Loiseau
*/
public class MavenITmng4720DependencyManagementExclusionMergeTest extends AbstractMavenIntegrationTestCase {
@ -39,11 +40,13 @@ public class MavenITmng4720DependencyManagementExclusionMergeTest extends Abstra
/**
* Verify the effective exclusions applied during transitive dependency resolution when both the regular
* dependency section and dependency management declare exclusions for a particular dependency.
* <p>
* By default, the dependency management of transitive dependencies is now taken into account.
*
* @throws Exception in case of failure
*/
@Test
public void testit() throws Exception {
public void testitWithTransitiveDependencyManager() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4720");
Verifier verifier = newVerifier(testDir.getAbsolutePath());
@ -63,7 +66,45 @@ public class MavenITmng4720DependencyManagementExclusionMergeTest extends Abstra
assertFalse(classpath.toString(), classpath.contains("b-0.1.jar"));
// should better have been excluded as well, now it's a matter of backward-compat
// dependency management in a excludes d
if (matchesVersionRange("[4.0.0-beta-5,)")) {
assertFalse(classpath.toString(), classpath.contains("d-0.1.jar"));
} else {
assertTrue(classpath.toString(), classpath.contains("d-0.1.jar"));
}
}
/**
* Verify the effective exclusions applied during transitive dependency resolution when both the regular
* dependency section and dependency management declare exclusions for a particular dependency.
* <p>
* This tests the same behaviour with dependency manager transitivity disabled.
*
* @throws Exception in case of failure
*/
@Test
public void testitWithTransitiveDependencyManagerDisabled() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4720");
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteArtifacts("org.apache.maven.its.mng4720");
verifier.addCliArgument("-s");
verifier.addCliArgument("settings.xml");
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
verifier.addCliArgument("-Dmaven.resolver.dependencyManagerTransitivity=false");
verifier.addCliArgument("validate");
verifier.execute();
verifier.verifyErrorFreeLog();
List<String> classpath = verifier.loadLines("target/classpath.txt", "UTF-8");
assertTrue(classpath.toString(), classpath.contains("a-0.1.jar"));
assertTrue(classpath.toString(), classpath.contains("c-0.1.jar"));
assertFalse(classpath.toString(), classpath.contains("b-0.1.jar"));
// backward-compat: dependency management is ignored except in root pom
assertTrue(classpath.toString(), classpath.contains("d-0.1.jar"));
}
}

View File

@ -0,0 +1,129 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.it;
import java.io.File;
import java.util.List;
import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;
/**
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-7982">MNG-7982</a>.
*
* @author Didier Loiseau
*/
public class MavenITmng7982DependencyManagementTransitivityTest extends AbstractMavenIntegrationTestCase {
public MavenITmng7982DependencyManagementTransitivityTest() {
super("[4.0.0-beta-5,)");
}
/**
* Verify the effective dependency versions determined when using the transitive dependency management (default).
* <p>
* By default, the dependency management of transitive dependencies should be taken into account.
*
* @throws Exception in case of failure
*/
@Test
public void testitWithTransitiveDependencyManager() throws Exception {
File testDir =
ResourceExtractor.simpleExtractResources(getClass(), "/mng-7982-transitive-dependency-management");
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.deleteArtifacts("org.apache.maven.its.mng7982");
verifier.addCliArgument("-s");
verifier.addCliArgument("settings.xml");
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
verifier.addCliArgument("verify");
verifier.execute();
verifier.verifyErrorFreeLog();
List<String> bClasspath = verifier.loadLines("b/target/classpath.txt", "UTF-8");
assertTrue(bClasspath.toString(), bClasspath.contains("a-1.jar"));
assertFalse(bClasspath.toString(), bClasspath.contains("a-2.jar"));
List<String> cClasspath = verifier.loadLines("c/target/classpath.txt", "UTF-8");
assertTrue(cClasspath.toString(), cClasspath.contains("b-1.jar"));
assertFalse(cClasspath.toString(), cClasspath.contains("a-1.jar"));
assertTrue(cClasspath.toString(), cClasspath.contains("a-2.jar"));
List<String> dClasspath = verifier.loadLines("d/target/classpath.txt", "UTF-8");
assertTrue(dClasspath.toString(), dClasspath.contains("c-1.jar"));
assertTrue(dClasspath.toString(), dClasspath.contains("b-1.jar"));
assertFalse(dClasspath.toString(), dClasspath.contains("a-1.jar"));
assertTrue(dClasspath.toString(), dClasspath.contains("a-2.jar"));
List<String> eClasspath = verifier.loadLines("e/target/classpath.txt", "UTF-8");
assertTrue(eClasspath.toString(), eClasspath.contains("d-1.jar"));
assertTrue(eClasspath.toString(), eClasspath.contains("c-1.jar"));
assertTrue(eClasspath.toString(), eClasspath.contains("b-1.jar"));
assertFalse(eClasspath.toString(), eClasspath.contains("a-1.jar"));
assertTrue(eClasspath.toString(), eClasspath.contains("a-2.jar"));
}
/**
* Verify the effective dependency versions determined when disabling the transitive dependency management (Maven 2/3 behavior).
* <p>
* When transitivity is disabled, the dependency management of transitive dependencies should is ignored.
*
* @throws Exception in case of failure
*/
@Test
public void testitWithTransitiveDependencyManagerDisabled() throws Exception {
File testDir =
ResourceExtractor.simpleExtractResources(getClass(), "/mng-7982-transitive-dependency-management");
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.deleteArtifacts("org.apache.maven.its.mng7982");
verifier.addCliArgument("-s");
verifier.addCliArgument("settings.xml");
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
verifier.addCliArgument("verify");
verifier.addCliArgument("-Dmaven.resolver.dependencyManagerTransitivity=false");
verifier.execute();
verifier.verifyErrorFreeLog();
List<String> bClasspath = verifier.loadLines("b/target/classpath.txt", "UTF-8");
assertTrue(bClasspath.toString(), bClasspath.contains("a-1.jar"));
assertFalse(bClasspath.toString(), bClasspath.contains("a-2.jar"));
List<String> cClasspath = verifier.loadLines("c/target/classpath.txt", "UTF-8");
assertTrue(cClasspath.toString(), cClasspath.contains("b-1.jar"));
assertFalse(cClasspath.toString(), cClasspath.contains("a-1.jar"));
assertTrue(cClasspath.toString(), cClasspath.contains("a-2.jar"));
List<String> dClasspath = verifier.loadLines("d/target/classpath.txt", "UTF-8");
assertTrue(dClasspath.toString(), dClasspath.contains("c-1.jar"));
assertTrue(dClasspath.toString(), dClasspath.contains("b-1.jar"));
// dependency management of c is ignored
assertTrue(dClasspath.toString(), dClasspath.contains("a-1.jar"));
assertFalse(dClasspath.toString(), dClasspath.contains("a-2.jar"));
List<String> eClasspath = verifier.loadLines("e/target/classpath.txt", "UTF-8");
assertTrue(eClasspath.toString(), eClasspath.contains("d-1.jar"));
assertTrue(eClasspath.toString(), eClasspath.contains("c-1.jar"));
assertTrue(eClasspath.toString(), eClasspath.contains("b-1.jar"));
// dependency management of c is ignored
assertTrue(dClasspath.toString(), dClasspath.contains("a-1.jar"));
assertFalse(dClasspath.toString(), dClasspath.contains("a-2.jar"));
}
}

View File

@ -120,6 +120,7 @@ public class TestSuiteOrdering implements ClassOrderer {
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
*/
suite.addTestSuite(MavenITmng7982DependencyManagementTransitivityTest.class);
suite.addTestSuite(MavenITmng8294ParentChecksTest.class);
suite.addTestSuite(MavenITmng8293BomImportFromReactor.class);
suite.addTestSuite(MavenITmng8288NoRootPomTest.class);

View File

@ -5,6 +5,8 @@
#4 mv bootstrap.txt tmp.txt && cat tmp.txt | sort -u > bootstrap.txt && rm tmp.txt
#5
com.google.code.findbugs:jsr305:1.3.9
com.google.errorprone:error_prone_annotations:2.16
com.google.errorprone:error_prone_annotations:2.19.1
com.google.guava:guava:10.0.1
com.google.guava:guava:16.0.1
com.thoughtworks.qdox:qdox:2.0-M9
@ -96,6 +98,7 @@ org.apache.maven.plugins:maven-ear-plugin:${stubPluginVersion}
org.apache.maven.plugins:maven-ear-plugin:3.2.0
org.apache.maven.plugins:maven-ejb-plugin:${stubPluginVersion}
org.apache.maven.plugins:maven-ejb-plugin:3.1.0
org.apache.maven.plugins:maven-enforcer-plugin:3.0.0
org.apache.maven.plugins:maven-help-plugin:3.3.0
org.apache.maven.plugins:maven-install-plugin:${stubPluginVersion}
org.apache.maven.plugins:maven-install-plugin:3.0.1
@ -110,6 +113,7 @@ org.apache.maven.plugins:maven-plugin-plugin:3.6.0
org.apache.maven.plugins:maven-plugin-plugin:3.9.0
org.apache.maven.plugins:maven-rar-plugin:${stubPluginVersion}
org.apache.maven.plugins:maven-release-plugin:3.0.0-M5
org.apache.maven.plugins:maven-remote-resources-plugin:1.7.0
org.apache.maven.plugins:maven-resources-plugin:${stubPluginVersion}
org.apache.maven.plugins:maven-resources-plugin:3.2.0
org.apache.maven.plugins:maven-resources-plugin:3.3.0
@ -151,6 +155,8 @@ org.apache.maven:maven-script-ant:2.1.0
org.apache.maven:maven-settings-builder:3.1.1
org.apache.maven:maven-settings:3.1.1
org.apache.maven.plugin-testing:maven-plugin-testing-harness:3.3.0
org.checkerframework:checker-qual:3.21.2
org.checkerframework:checker-qual:3.35.0
org.codehaus.gmavenplus:gmavenplus-plugin:1.11.0
org.codehaus.modello:modello-maven-plugin:2.1.1
org.codehaus.mojo:build-helper-maven-plugin:3.2.0

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.1.0</modelVersion>
<parent />
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>b</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>a</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.1.0</modelVersion>
<parent />
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>c</artifactId>
<version>1</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>a</artifactId>
<version>2</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>b</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.1.0</modelVersion>
<parent />
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>d</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>c</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.1.0</modelVersion>
<parent />
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>e</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>d</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project root="true">
<modelVersion>4.1.0</modelVersion>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-7982</name>
<description>Verify that the effective versions selected during transitive dependency resolution
are those coming from the dependency management of the transitive dependencies.</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-dependency-resolution</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<compileClassPath>target/classpath.txt</compileClassPath>
<significantPathLevels>1</significantPathLevels>
</configuration>
<executions>
<execution>
<id>resolve</id>
<goals>
<goal>compile</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,3 @@
*.pom text eol=lf
maven-metadata.xml text eol=lf

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.1.0</modelVersion>
<parent />
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>a</artifactId>
<version>1</version>
<name>a1</name>
</project>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>a</artifactId>
<version>1</version>
<name>a1</name>
<description>Verify that the effective versions selected during transitive dependency resolution
are those coming from the dependency management of the transitive dependencies.</description>
</project>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.1.0</modelVersion>
<parent />
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>a</artifactId>
<version>2</version>
<name>a2</name>
</project>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>a</artifactId>
<version>2</version>
<name>a2</name>
<description>Verify that the effective versions selected during transitive dependency resolution
are those coming from the dependency management of the transitive dependencies.</description>
</project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://maven.apache.org/METADATA/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/METADATA/1.1.0 https://maven.apache.org/xsd/repository-metadata-1.1.0.xsd">
<groupId>org.apache.maven.its.mng7982</groupId>
<artifactId>a</artifactId>
<versioning>
<release>1</release>
<versions>
<version>2</version>
<version>1</version>
</versions>
<lastUpdated>20241006201419</lastUpdated>
</versioning>
</metadata>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<settings>
<profiles>
<profile>
<id>maven-core-it-repo</id>
<repositories>
<repository>
<id>maven-core-it</id>
<url>@baseurl@/repo</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>maven-core-it-repo</activeProfile>
</activeProfiles>
</settings>