From 41391bd61dfdca5b2e06dcfe61bea9271dd1340f Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Tue, 11 Aug 2026 20:08:09 +0200 Subject: [PATCH] RemoveDuplicateDependencies: add failing test for duplicates differing only in scope Pins the coverage gap where two declarations of the same dependency differing only in are left alone, although Maven's effective model resolves them to a single dependency with the last declaration winning (verified with Maven 3.9.16, which also warns "must be unique"). Note the existing keepDependencyWithDifferentScope test pins the opposite outcome for this shape, so closing the gap means changing that expectation; the pull request description presents both sides. Marked as known-failing with @Disabled since junit-pioneer is not on the rewrite-maven test classpath. --- .../RemoveDuplicateDependenciesTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveDuplicateDependenciesTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveDuplicateDependenciesTest.java index cb019d1d712..0e6877e8ba3 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveDuplicateDependenciesTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveDuplicateDependenciesTest.java @@ -15,6 +15,7 @@ */ package org.openrewrite.maven; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; import org.openrewrite.Issue; @@ -409,6 +410,56 @@ void keepDependencyWithDifferentScope() { ); } + @Disabled("DependencyKey includes scope, so declarations differing only in scope are not detected, though Maven resolves them to one dependency; the existing keepDependencyWithDifferentScope test pins the opposite outcome, so a fix must change that expectation too") + @Test + void removeDuplicatedDependencyDifferingOnlyInScope() { + rewriteRun( + pomXml( + """ + + 4.0.0 + + com.mycompany.app + my-app + 1 + + + + junit + junit + 4.13.1 + + + junit + junit + 4.13.1 + test + + + + """, + """ + + 4.0.0 + + com.mycompany.app + my-app + 1 + + + + junit + junit + 4.13.1 + test + + + + """ + ) + ); + } + @Test void removeDuplicatedDependencyWithImportScope() { rewriteRun(