diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveProperty.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveProperty.java index c45af9f319f..15e3e27dbd0 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveProperty.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveProperty.java @@ -21,6 +21,7 @@ import org.openrewrite.Option; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; +import org.openrewrite.xml.RemoveContentVisitor; import org.openrewrite.xml.tree.Xml; @Value @@ -51,7 +52,8 @@ private class RemovePropertyVisitor extends MavenVisitor { @Override public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) { if (isPropertyTag() && propertyName.equals(tag.getName())) { - return null; + doAfterVisit(new RemoveContentVisitor<>(tag, true)); + maybeUpdateModel(); } return super.visitTag(tag, ctx); } diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/RemovePropertyTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/RemovePropertyTest.java index 79137f4c6a1..ec7da455a79 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/RemovePropertyTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/RemovePropertyTest.java @@ -64,4 +64,34 @@ void removeProperty() { ) ); } + + @Test + void removeOnlyProperty() { + rewriteRun( + pomXml( + """ + + 4.0.0 + + com.mycompany.app + my-app + 1 + + + b + + + """, + """ + + 4.0.0 + + com.mycompany.app + my-app + 1 + + """ + ) + ); + } }