You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/10/24 06:42:23 UTC
[maven-integration-testing] 01/03: - Add test demonstrating the
issue where the wrong repositories are used for resolving transitive
dependencies
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MNG-6759
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git
commit fb8e4b69b2e0afc6c04ebf172720d497c007ffa7
Author: Stig Rohde Døssing <st...@gmail.com>
AuthorDate: Sat Oct 12 18:34:20 2019 +0200
- Add test demonstrating the issue where the wrong repositories are used for resolving transitive dependencies
---
...ng6759TransitiveDependencyRepositoriesTest.java | 64 ++++++++++++++++++++
.../dependency-in-custom-repo/pom.xml | 19 ++++++
.../module1/pom.xml | 18 ++++++
.../module2/pom.xml | 25 ++++++++
.../pom.xml | 32 ++++++++++
.../pom.xml | 70 ++++++++++++++++++++++
.../apache/maven/its/mng6759/plugin/TestMojo.java | 66 ++++++++++++++++++++
7 files changed, 294 insertions(+)
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6759TransitiveDependencyRepositoriesTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6759TransitiveDependencyRepositoriesTest.java
new file mode 100644
index 0000000..3ef06e7
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6759TransitiveDependencyRepositoriesTest.java
@@ -0,0 +1,64 @@
+package org.apache.maven.it;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.net.URI;
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * This is a test for <a href="https://issues.apache.org/jira/browse/MNG-6759">MNG-6759</a>.
+ */
+public class MavenITmng6759TransitiveDependencyRepositoriesTest extends AbstractMavenIntegrationTestCase {
+
+ private final String projectBaseDir = "/mng-6759-transitive-dependency-repositories";
+
+ public MavenITmng6759TransitiveDependencyRepositoriesTest() {
+ super( "(,3.6.1],[3.6.3,)" );
+ }
+
+ /**
+ * Verifies that a project with a dependency graph like A -> B -> C,
+ * where C is in a non-Central repository should use B's {@literal <repositories>} to resolve C.
+ */
+ public void testTransitiveDependenciesAccountForRepositoriesListedByDependencyTrailPredecessor() throws Exception {
+ URI customRepoUri = installDependencyCInCustomRepo();
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), projectBaseDir );
+
+ Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+
+ verifier.addCliOption( "-Dcustom.repo.uri=" + customRepoUri );
+ verifier.executeGoal( "package" );
+ verifier.verifyErrorFreeLog();
+ }
+
+ private URI installDependencyCInCustomRepo() throws Exception {
+ File dependencyCProjectDir = ResourceExtractor.simpleExtractResources( getClass(), projectBaseDir + "/dependency-in-custom-repo" );
+ URI customRepoUri = new File(new File(dependencyCProjectDir, "target" ), "repo" ).toURI();
+ Verifier verifier = newVerifier( dependencyCProjectDir.getAbsolutePath() );
+
+ verifier.deleteDirectory( "target" );
+ verifier.addCliOption( "-DaltDeploymentRepository=customRepo::default::" + customRepoUri );
+ verifier.executeGoal( "deploy" );
+ verifier.verifyErrorFreeLog();
+ return customRepoUri;
+ }
+
+}
diff --git a/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/dependency-in-custom-repo/pom.xml b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/dependency-in-custom-repo/pom.xml
new file mode 100644
index 0000000..2089f05
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/dependency-in-custom-repo/pom.xml
@@ -0,0 +1,19 @@
+<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>mng-6759-transitive-dependency-repositories</groupId>
+ <artifactId>dependency-in-custom-repo</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module1/pom.xml b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module1/pom.xml
new file mode 100644
index 0000000..3c655d7
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module1/pom.xml
@@ -0,0 +1,18 @@
+<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>mng-6759-transitive-dependency-repositories</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>module1</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>mng-6759-transitive-dependency-repositories</groupId>
+ <artifactId>module2</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module2/pom.xml b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module2/pom.xml
new file mode 100644
index 0000000..c0c3041
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module2/pom.xml
@@ -0,0 +1,25 @@
+<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>mng-6759-transitive-dependency-repositories</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>module2</artifactId>
+
+ <repositories>
+ <repository>
+ <id>customRepo</id>
+ <url>${custom.repo.uri}</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>mng-6759-transitive-dependency-repositories</groupId>
+ <artifactId>dependency-in-custom-repo</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/pom.xml b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/pom.xml
new file mode 100644
index 0000000..e75beb7
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/pom.xml
@@ -0,0 +1,32 @@
+<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>mng-6759-transitive-dependency-repositories</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>module1</module>
+ <module>module2</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <!-- This plugin resolves dependencies via DefaultLegacyArtifactCollector, which hits the buggy code in MavenMetadataSource -->
+ <groupId>org.apache.maven.its.plugins</groupId>
+ <artifactId>mng-6759-resolves-project-dependencies-plugin</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>resolve</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/core-it-support/core-it-plugins/mng6759-plugin-resolves-project-dependencies/pom.xml b/core-it-support/core-it-plugins/mng6759-plugin-resolves-project-dependencies/pom.xml
new file mode 100644
index 0000000..ff055d8
--- /dev/null
+++ b/core-it-support/core-it-plugins/mng6759-plugin-resolves-project-dependencies/pom.xml
@@ -0,0 +1,70 @@
+<?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 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>
+
+ <parent>
+ <artifactId>maven-it-plugins</artifactId>
+ <groupId>org.apache.maven.its.plugins</groupId>
+ <version>2.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>mng-6759-resolves-project-dependencies-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+
+ <properties>
+ <maven-version>3.0</maven-version>
+ </properties>
+
+ <name>Maven IT Plugin :: mng-6759 plugin</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-artifact-resolver</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${maven-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>${maven-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/core-it-support/core-it-plugins/mng6759-plugin-resolves-project-dependencies/src/main/java/org/apache/maven/its/mng6759/plugin/TestMojo.java b/core-it-support/core-it-plugins/mng6759-plugin-resolves-project-dependencies/src/main/java/org/apache/maven/its/mng6759/plugin/TestMojo.java
new file mode 100644
index 0000000..bda4785
--- /dev/null
+++ b/core-it-support/core-it-plugins/mng6759-plugin-resolves-project-dependencies/src/main/java/org/apache/maven/its/mng6759/plugin/TestMojo.java
@@ -0,0 +1,66 @@
+package org.apache.maven.its.mng6759.plugin;
+
+/*
+ * 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.
+ */
+
+import java.util.Arrays;
+import org.apache.maven.ProjectDependenciesResolver;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Resolves the project dependency tree
+ */
+@Mojo( name = "resolve", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true )
+public class TestMojo
+ extends AbstractMojo
+{
+
+ @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ private MavenProject project;
+
+ @Parameter( defaultValue = "${session}", readonly = true, required = true )
+ private MavenSession mavenSession;
+
+ @Component( hint = "default" )
+ protected ProjectDependenciesResolver dependencyResolver;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+
+ try
+ {
+ dependencyResolver.resolve( project, Arrays.asList( "test" ), mavenSession );
+ }
+ catch ( ArtifactResolutionException | ArtifactNotFoundException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+
+ }
+}