The OpenRewriteRecipe
transform allows you to apply any Open Rewrite Recipe to a set of files and gather the results.
Note: Currently, only Java related recipes are supported. The engine leverages version
7.0.0
of Open Rewrite and parses Java files using the grammar for Java 11.
type: OpenRewriteRecipe
recipe: <string> # Full qualified classname of the recipe
options:
<string>: <SpEL expression> # Keys and values depend on the class of the recipe
<string>: <SpEL expression> # Refer to the documentation of said recipe
...
The following example applies the ChangePackage Recipe to a set of Java files in the com.acme
package and moves them to the value of #companyPkg
. This is more powerful than using RewritePath and ReplaceText, as it reads the syntax of files and correctly deals with imports, fully vs. non-fully qualified names, and so on.
chain:
- include: ["**/*.java"]
- type: OpenRewriteRecipe
recipe: org.openrewrite.java.ChangePackage
options:
oldFullyQualifiedPackageName: "'com.acme'"
newFullyQualifiedPackageName: "#companyPkg"
recursive: true