Repository navigation
Maven: fold a renamed dependency into an existing declaration of another scope - #9061
Merged
Merged
Conversation
… into an existing declaration of another scope Maven keys a dependency on groupId:artifactId:type:classifier, so a renamed declaration that only differs in scope from an existing one is a duplicate: Maven 3 warns and lets the last declaration win, Maven 4 fails the build. `ChangeDependencyGroupIdAndArtifactId` now removes the old declaration in that case too, and widens the scope of the surviving one to cover both.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ChangeDependencyGroupIdAndArtifactIdrenames a dependency declaration in place. Since #8129 it removes the renamed declaration instead when the pom already declares the new coordinates, but only if classifier, type and scope all match. When only the scope differs, the pom ends up with two declarations of the samegroupId:artifactId:type:classifier. Maven 3 warns about that and lets the last declaration win, which can silently narrow a compile dependency to test scope. Maven 4 fails the build with "must be unique".What changes:
systemorimport, is left as it was.Recipes that rename onto coordinates a pom already declares in another scope now remove a declaration where they used to leave two, and may widen the scope of the one that remains.
Found by coding agents reviewing a run of
org.openrewrite.java.testing.mockito.ReplacePowerMockitoover six repositories. Inkonik32/openrest,pom.xmldeclaresmockito-corein compile scope andpowermock-api-mockitoin test scope, and the migration turned the second into anothermockito-core.victorrentea/design-patternshas the same shape. The agents wrote the problem up asduplicate-dependency-different-scope. They report that with this change the migration, built from source and run on each of the two repositories, leaves onemockito-coredeclaration.ChangeDependencyGroupIdAndArtifactIdTestpasses, 75 tests with one skipped, four of them added here: one for each scope combination above. They follow the fixtures of the existing deduplication tests in that class, not the poms of the two repositories.Known limits:
design-patternsthat movesmockito-coreto the version Spring Boot manages.<exclusions>and<optional>of the removed declaration are not carried over to the remaining one.<dependencies>are folded together.ChangeManagedDependencyGroupIdAndArtifactIdis unchanged.