Skip to content

Add RemoveRedundantDependencyVersions.Skip marker#6852

Draft
Jenson3210 wants to merge 7 commits intomainfrom
Jenson3210/retain-explicit-version
Draft

Add RemoveRedundantDependencyVersions.Skip marker#6852
Jenson3210 wants to merge 7 commits intomainfrom
Jenson3210/retain-explicit-version

Conversation

@Jenson3210
Copy link
Contributor

@Jenson3210 Jenson3210 commented Mar 2, 2026

Summary

  • Add a Skip marker nested class in RemoveRedundantDependencyVersions that prevents version removal when present on a dependency tag
  • Check for the marker in both isDependencyTag() and isManagedDependencyTag() branches of visitTag
  • Revert the previous retainExplicitVersion flag approach in favor of this marker-based design

Problem

When UpgradeDependencyVersion upgrades a dependency to match the parent-managed version, RemoveRedundantDependencyVersions subsequently removes the explicit <version> tag. In some cases, users want to retain the explicit version even when it matches the managed version, but there was no way for an earlier recipe to signal this intent.

Solution

Instead of adding a configuration flag to UpgradeDependencyVersion, introduce a RemoveRedundantDependencyVersions.Skip marker that any recipe can place on a <dependency> tag. When RemoveRedundantDependencyVersions encounters this marker, it skips version removal for that tag. This keeps the mechanism generic and avoids adding recipe-specific boolean flags.

Test plan

  • Existing RemoveRedundantDependencyVersionsTest tests pass (56 tests)
  • New SkipMarker nested test class with two tests:
    • dependencyWithSkipMarkerKeepsVersion - version preserved when marker present
    • dependencyWithoutSkipMarkerHasVersionRemoved - default behavior unchanged
  • UpgradeDependencyVersionTest tests pass

Fixes moderneinc/customer-requests#1942

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Mar 2, 2026
@timtebeek timtebeek changed the title Add retainExplicitVersion option to UpgradeDependencyVersion Add retainExplicitVersion option to UpgradeDependencyVersion Mar 2, 2026
Comment on lines 309 to 312
doAfterVisit(new RemoveRedundantDependencyVersions(null, null, null, retainVersions).getVisitor());
doAfterVisit(upgradeManagedDependency);
maybeUpdateModel();
doAfterVisit(new RemoveRedundantDependencyVersions(null, null, null, null).getVisitor());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there not the possibility that their explicit versions will be wiped out anyway at some point if something like this is reached (possibly even for a different invocation of UpgradeDependencyVersion that is unrelated)?

@Jenson3210 Jenson3210 changed the title Add retainExplicitVersion option to UpgradeDependencyVersion Add RemoveRedundantDependencyVersions.Skip marker Mar 3, 2026
@Jenson3210 Jenson3210 marked this pull request as draft March 3, 2026 10:04
Jenson3210 and others added 7 commits March 3, 2026 12:25
When set to true, this flag prevents the recipe from removing explicit
version tags that match the parent-managed version after an upgrade.
This is useful when organizations want to keep version tags in child
POMs for clarity or policy reasons.

A backward-compatible constructor is preserved alongside the new
@JsonCreator constructor that accepts the additional parameter.

Fixes moderneinc/customer-requests#1942
Co-authored-by: Tim te Beek <tim@moderne.io>
Remove the retainExplicitVersion field, constructors, and conditional
logic from UpgradeDependencyVersion in favor of a more flexible
Skip marker on RemoveRedundantDependencyVersions.
Add a Skip marker that can be placed on a Maven dependency tag to
prevent RemoveRedundantDependencyVersions from removing its explicit
<version>. This allows other recipes to preserve intentionally set
versions by adding the marker before RemoveRedundantDependencyVersions
runs.

Fixes moderneinc/customer-requests#1942
Remove unnecessary expectedCyclesThatMakeChanges and add mixed-state
test that verifies the Skip marker only affects the marked dependency
while unmarked dependencies still have their redundant versions removed.
@Jenson3210 Jenson3210 force-pushed the Jenson3210/retain-explicit-version branch from ad39cb7 to a4a176d Compare March 3, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants