Search code examples
javareplaceopenrewrite

Openrewrite stops after first successfull replacement recipe


I want to use Openrewrite and have a small "Hello Europe" Class with a simple

System.out.println("Hello Europe!");

My rewrite.yml consists of two recipes to execute after another Europe -> World and then World -> Universe:

---
type: specs.openrewrite.org/v1beta/recipe
name: company.TestReplaceText
recipeList:
  - org.openrewrite.text.FindAndReplace:
      regex: false
      find: Europe
      replace: World
      filePattern: '**/*.java'
  - org.openrewrite.text.FindAndReplace:
      regex: false
      find: World
      replace: Universe
      filePattern: '**/*.java'

So I expected the call of mvn rewrite:run would change first "Europe" in "World" (first recipe) and after that "World" into "Universe" (second recipe).

Instead of it, Openrewrite just applies the first recipe and skips the second one:

[INFO] Running recipe(s)...
[WARNING] Changes have been made to src/main/java/HelloSomeone.java by:
[WARNING]     company.TestReplaceText
[WARNING]         org.openrewrite.text.FindAndReplace: {find=Europe, replace=World, regex=false, filePattern=**/*.java}
[WARNING] Please review and commit the results.

I need a second call of mvn rewrite:run for the second recipe to be successfull applied:

[INFO] Running recipe(s)...
[WARNING] Changes have been made to src/main/java/HelloSomeone.java by:
[WARNING]     company.TestReplaceText
[WARNING]         org.openrewrite.text.FindAndReplace: {find=World, replace=Universe, regex=false, filePattern=**/*.java}
[WARNING] Please review and commit the results.

Why? and can I do something against it?

Remark: the second recipe is not applied at all. With the original code

    System.out.println("Hello Europe!");
    System.out.println("Hello World!");

the call of mvn change it into

    System.out.println("Hello World!");
    System.out.println("Hello World!");

Solution

  • I used the old version 5.2.6 of the maven plugin. With version 5.32.1, no problem anymore.