diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RenamePropertyKey.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RenamePropertyKey.java index 0d5f6b527c0..da620564608 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RenamePropertyKey.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RenamePropertyKey.java @@ -73,6 +73,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { Xml.Tag t = super.visitTag(tag, ctx); if (isPropertyTag() && oldKey.equals(t.getName())) { t = t.withName(newKey); + maybeUpdateModel(); } if (t.getChildren().isEmpty()) { Optional value = t.getValue(); diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java index 68092d175f6..0a865ea5a93 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java @@ -173,4 +173,53 @@ void propertyInProperty() { ) ); } + + @Test + void renamePropertyAndValue() { + String yamlRecipe = """ + --- + type: specs.openrewrite.org/v1beta/recipe + name: org.openrewrite.RenamePropertyAndValue + displayName: RenamePropertyAndValue + description: RenamePropertyAndValue description + recipeList: + - org.openrewrite.maven.RenamePropertyKey: + oldKey: "abc" + newKey: "def" + - org.openrewrite.maven.ChangePropertyValue: + key: "def" + newValue: "2.0" + """; + rewriteRun( + spec -> spec.recipeFromYaml(yamlRecipe, "org.openrewrite.RenamePropertyAndValue"), + pomXml( + """ + + 4.0.0 + + + 1.0 + + + com.mycompany.app + my-app + 1 + + """, + """ + + 4.0.0 + + + 2.0 + + + com.mycompany.app + my-app + 1 + + """ + ) + ); + } }