I like to create a single Openrewrite migration jar that includes custom recipes and rewrite.yml recipes.
I would like it to be executed using only a one liner maven call without altering the current pom like:
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=com.myorg:rewrite-migrate:1.0.0 \
-Drewrite.activeRecipes=com.myorg.My1To2Migration
I can place a rewrite.yml in the jar at location src\main\resources\META-INF\rewrite.yml
containing different standard recipes with my configurations.
I also can place a custom recipe My1To2Migration
that returns a list of standard recipes like:
@Override
public List<Recipe> getRecipeList() {
return Arrays
.asList(
new ChangeType("com.myorg.OldType", "com.myorg.NewType", false)
);
}
But, as far as I know, for execution I need to add both recipes as activeRecipes
to the command line:
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=com.myorg:rewrite-migrate:1.0.0 \
-Drewrite.activeRecipes=com.myorg.My1To2Migration,com.myorg.RecipeFromRewriteYml
Or add them all in the pom:
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.4.2</version>
<configuration>
<activeRecipes>
<recipe>com.myorg.My1To2Migration</recipe>
<recipe>com.myorg.RecipeFromRewriteYml</recipe>
</activeRecipes>
</configuration>
</plugin>
Is there a way to include the custom recipes from the rewrite.yml
into the List<Recipe> getRecipeList()
so that I only have to add My1To2Migration
to the maven command activeRecipes
?
For example like this pseudo code to get the idea:
@Override
public List<Recipe> getRecipeList() {
return Arrays
.asList(
new ChangeType("com.myorg.OldType", "com.myorg.NewType", false),
new RecipeFromYaml("rewrite.yml")
);
}
Or maybe through another mechanism ?
You'll want to place your rewrite.yml
file in
src\main\resources\META-INF\rewrite\your-recipes.yml
; your path was missing in the \rewrite\
folder. It's then likely easiest to refer to the fully qualified class name of My1To2Migration
from your yaml file, rather than from your custom recipe. Hope that helps!