Skip to content

Fix ChangeManagedDependencyGroupIdAndArtifactId overwriting artifactId with glob pattern#6783

Merged
timtebeek merged 2 commits intomainfrom
fix/managed-dependency-glob-artifactid
Feb 22, 2026
Merged

Fix ChangeManagedDependencyGroupIdAndArtifactId overwriting artifactId with glob pattern#6783
timtebeek merged 2 commits intomainfrom
fix/managed-dependency-glob-artifactid

Conversation

@timtebeek
Copy link
Member

Summary

  • Fix ChangeManagedDependencyGroupIdAndArtifactId incorrectly overwriting the artifactId XML tag with a literal glob string (e.g. swagger-*) when ChangeDependencyGroupIdAndArtifactId is invoked with a wildcard oldArtifactId and newArtifactId=null
  • Only change groupId/artifactId tags when the new value actually differs from the old value; when they match (glob passthrough), preserve the original tag value
  • Read actual groupId/artifactId from the XML tag for version resolution instead of using potentially-glob values

Test plan

  • Added globArtifactIdRetainedWhenNewMatchesOld test in ChangeManagedDependencyGroupIdAndArtifactIdTest
  • All existing ChangeManagedDependencyGroupIdAndArtifactIdTest tests pass
  • All existing ChangeDependencyGroupIdAndArtifactIdTest tests pass
  • Full rewrite-maven test suite passes

…d with glob pattern

When ChangeDependencyGroupIdAndArtifactId is invoked with a wildcard
oldArtifactId (e.g. "swagger-*") and newArtifactId=null, the managed
dependency handler incorrectly overwrites the artifactId XML tag with
the literal glob string instead of preserving the original value.

Only change groupId/artifactId tags when the new value actually differs
from the old value. When they match (glob passthrough), preserve the
original tag value. Also read actual groupId/artifactId from the XML
tag for version resolution instead of using potentially-glob values.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Feb 20, 2026
@timtebeek timtebeek changed the title Fix ChangeManagedDependencyGroupIdAndArtifactId overwriting artifactId with glob pattern Fix ChangeManagedDependencyGroupIdAndArtifactId overwriting artifactId with glob pattern Feb 20, 2026
@timtebeek timtebeek marked this pull request as draft February 20, 2026 14:16
@timtebeek timtebeek force-pushed the fix/managed-dependency-glob-artifactid branch from 92ffd14 to e2bedca Compare February 20, 2026 14:56
String resolvedGroupId = t.getChildValue("groupId").orElse(newGroupId != null ? newGroupId : oldGroupId);
String resolvedArtifactId = t.getChildValue("artifactId").orElse(newArtifactId != null ? newArtifactId : oldArtifactId);
if (resolvedArtifactId.contains("${")) {
ResolvedPom pom = getResolutionResult().getPom();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could reduce some repetition if we extract this outside of the if and use it here, in the next if and for the getValue(..) call for setting the resolvedNewVersion

@timtebeek timtebeek force-pushed the fix/managed-dependency-glob-artifactid branch from e2bedca to 6bc827f Compare February 20, 2026 16:28
@timtebeek timtebeek marked this pull request as ready for review February 20, 2026 16:36
@timtebeek timtebeek added bug Something isn't working recipe Requested Recipe maven labels Feb 20, 2026
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Feb 20, 2026
…ation

ChangeDependencyGroupIdAndArtifactId was passing glob patterns (e.g.
"swagger-*") as concrete newArtifactId/newGroupId values when delegating
to ChangeManagedDependencyGroupIdAndArtifactId. Fix the root cause by
making newGroupId/newArtifactId nullable (null = preserve existing value)
and passing them directly instead of falling back to old glob values.

Also move the duplicate dependency check from visitDocument into visitTag
so it uses the actual tag coordinates rather than potentially-null or
glob new values.
@timtebeek timtebeek force-pushed the fix/managed-dependency-glob-artifactid branch from 7e033d4 to de82343 Compare February 21, 2026 22:40
@timtebeek timtebeek merged commit 2af0299 into main Feb 22, 2026
1 check passed
@timtebeek timtebeek deleted the fix/managed-dependency-glob-artifactid branch February 22, 2026 16:41
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working maven recipe Requested Recipe

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants