Search code examples
openrewrite

How can I customize the OpenRewrite declarative YAML recipe name, location and split it?


I'm trying out OpenRewrite's declarative YAML format and I got it to work if I put all my recipes in a single file (rewrite.yml) in the root of the project.

So at the moment my demo's tree looks like this:

demo
│   build.gradle
│   gradlew
│   gradlew.bat
│   ...
│   rewrite.yml
│   settings.gradle
|
├───gradle
│   └───rewrite
│          init.gradle
...

and I run it like this:

.\gradlew rewriteDryRun --init-script gradle\rewrite\init.gradle "-Drewrite.activeRecipe=my.domein.MyRecipe"

Is there a way to

  • put the rewrite.yml somewhere else, eg under gradle/rewrite/?
  • give an other name, eg my-recipes.yml?
  • group my recipes in seperate files, eg my-recipes-for-issue1.yml, my-recipes-for-issue2.yml, etc?

Solution

  • Yes; the recommended pattern there is to fork this repository, and then add your recipes in separate files under src/main/resources/META-INF/rewrite/: https://github.com/moderneinc/rewrite-recipe-starter/tree/main/src/main/resources/META-INF/rewrite

    There's also an exercise that handles this exact topic: https://docs.moderne.io/user-documentation/workshops/recipe-authoring/#exercise-2-create-and-test-your-own-recipe-module