Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REGRESSION] Maven fails to use <repositories> section from dependenc…
…y when resolving transitive dependencies in some cases
- Loading branch information
Showing
9 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...src/test/java/org/apache/maven/it/MavenITmng6759TransitiveDependencyRepositoriesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.2),(3.6.2,)" ); | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...t/resources/mng-6759-transitive-dependency-repositories/dependency-in-custom-repo/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
18 changes: 18 additions & 0 deletions
18
core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module1/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
25 changes: 25 additions & 0 deletions
25
core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/module2/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
32 changes: 32 additions & 0 deletions
32
core-it-suite/src/test/resources/mng-6759-transitive-dependency-repositories/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
70 changes: 70 additions & 0 deletions
70
core-it-support/core-it-plugins/mng6759-plugin-resolves-project-dependencies/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
66 changes: 66 additions & 0 deletions
66
...lves-project-dependencies/src/main/java/org/apache/maven/its/mng6759/plugin/TestMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters