Problem
org.openrewrite.maven.AddProfile unconditionally removes and re-adds a profile with the same id on every recipe cycle, even when the existing profile already matches the desired state. This makes it non-idempotent.
The relevant code in AddProfile.java:
if (maybeProfile.isPresent()) {
Xml.Tag profile = maybeProfile.get();
t = (Xml.Tag) new RemoveContentVisitor(profile, false, false)
.visitNonNull(t, ctx, getCursor().getParentOrThrow());
}
// Always adds, even if the existing profile was identical
Xml.Tag profileTag = Xml.Tag.build(...);
t = (Xml.Tag) new AddToTagVisitor<>(profiles, profileTag)
.visitNonNull(t, ctx, getCursor().getParentOrThrow());
Impact
Any recipe using AddProfile will always report changes, even on the second cycle when nothing should change. Tests that use AddProfile need expectedCyclesThatMakeChanges(2) as a workaround.
Suggested Fix
Before removing and re-adding, compare the existing profile tag content to the one being built. If they're equivalent, return early without making changes.
Problem
org.openrewrite.maven.AddProfileunconditionally removes and re-adds a profile with the sameidon every recipe cycle, even when the existing profile already matches the desired state. This makes it non-idempotent.The relevant code in
AddProfile.java:Impact
Any recipe using
AddProfilewill always report changes, even on the second cycle when nothing should change. Tests that useAddProfileneedexpectedCyclesThatMakeChanges(2)as a workaround.Suggested Fix
Before removing and re-adding, compare the existing profile tag content to the one being built. If they're equivalent, return early without making changes.