openrewrite / openrewrite/rewrite
Maven Resolution - third+ order dependencies are inaccurately prioritizing versions from declaring dependency's depMgmt over declaring dependency's dependencies
Open
Nobody has claimed this yet.
bug
maven
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
The title is a mouthful -- this test case is probably easier to understand (the assertion matches Maven's behavior):
@Test
void transitiveDependencyVersionPriority() {
rewriteRun(
mavenProject("test-1.0.0",
pomXml("""
<?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>org.sample.foobar</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
</project>
""")),
mavenProject("test-1.2.3",
pomXml("""
<?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>org.sample.foobar</groupId>
<artifactId>test</artifactId>
<version>1.2.3</version>
</project>
""")),
mavenProject("middle-dep-parent",
pomXml("""
<?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>org.sample.foobar</groupId>
<artifactId>middle-dep-parent</artifactId>
<version>1.0.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.sample.foobar</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
""")),
mavenProject("middle-dep",
pomXml("""
<?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>org.sample.foobar</groupId>
<artifactId>middle-dep-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>org.sample.foobar</groupId>
<artifactId>middle-dep</artifactId>
<version>1.2.3</version>
<dependencies>
<dependency>
<groupId>org.sample.foobar</groupId>
<artifactId>test</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
""")),
mavenProject("client-project",
pomXml("""
<?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>org.sample.foobar</groupId>
<artifactId>client-project</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.sample.foobar</groupId>
<artifactId>middle-dep</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
""",
spec -> spec.afterRecipe(afterDoc -> assertThat(afterDoc.getMarkers().findFirst(MavenResolutionResult.class).orElseThrow()
.findDependencies("org.sample.foobar", "test", Scope.Compile))
.singleElement()
.matches(it -> it.getVersion().equals("1.2.3"), "is version 1.2.3 as defined in middle-dep"))
// fails, as org.sample.foobar:test resolves to version 1.0.0
))
);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the transitiveDependencyVersionPriority test case and inspect MavenResolutionResult.findDependencies for the client-project dependency graph. Reproduce the failure with the provided Maven projects, then verify that the resolved test dependency uses version 1.2.3 from middle-dep's dependencies rather than version 1.0.0 from its dependencyManagement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100