Don't pin explicit version on a renamed dep managed only by a remote ancestor parent#7498
Don't pin explicit version on a renamed dep managed only by a remote ancestor parent#7498
Conversation
Maven Central now resolves the `5.x` selector to 5.14.4 after the JUnit Jupiter 5.14.4 release, so the hardcoded expected version had to be bumped.
…ancestor parent ChangeDependencyGroupIdAndArtifactId previously added an explicit <version> to the renamed artifact whenever the new GAV was not in the resolved dependencyManagement chain. That is correct for projects that manage versions locally (own <dependencyManagement> or a BOM import), but pinned versions unnecessarily for projects whose parent is a custom wrapper that itself extends a managed parent (e.g. spring-boot-starter-parent). Skip the pin when the old dep is managed transitively AND no local <dependencyManagement> exists in the project's own POM or any local-parent POM. In that case the user is in a parent-managed workflow and the new managed version will flow through once the wrapper parent is upgraded. The local-management lookup is cached as a per-document field on the visitor, matching the existing visitor-field pattern used for availableVersions and safeVersionPlaceholdersToChange. Adds a synthetic Maven test (doesNotPinVersionWhenOldDepManagedOnlyByRemoteAncestor) that publishes a wrapper parent via withLocalRepository and asserts that javax.activation:javax.activation-api -> jakarta.activation:jakarta.activation-api is renamed without an explicit version.
…nt-fix # Conflicts: # rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java
|
Pulling this PR back at this stage. The test shows we would break version pinning, which is a crucial building block of security remediations. |
Summary
ChangeDependencyGroupIdAndArtifactIdpreviously added an explicit<version>to the renamed artifact whenever the new GAV was not in the resolveddependencyManagementchain. That is correct for projects that manage versions locally (own<dependencyManagement>or a BOM import), but pinned versions unnecessarily for projects whose parent is a custom wrapper that itself extends a managed parent (e.g.spring-boot-starter-parent).isDependencyManaged, which walks the mergeddependencyManagementlist) AND no local<dependencyManagement>exists in the project's own POM or any local-parent POM (newhasLocalDependencyManagementhelper). The lookup is cached per-document on the visitor, matching the existing pattern used foravailableVersionsandsafeVersionPlaceholdersToChange.managedToUnmanagedExternalizedDepMgmt,managedToUnmanagedWithoutChangeManagedDependency) still pin, becausehasLocalDependencyManagementreturns true.junit-jupiterversion innoDependencyManagementSectionfrom5.14.3to5.14.4(a separate one-line maintenance fix; Maven Central now resolves5.xto5.14.4).Test plan
ChangeDependencyGroupIdAndArtifactIdTest.doesNotPinVersionWhenOldDepManagedOnlyByRemoteAncestor— synthetic wrapper-parent scenario viawithLocalRepository. Fails onmain, passes with the fix../gradlew :rewrite-maven:test --tests "org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactIdTest"— all 62 tests pass after the JUnit version bump.