OpenRewriteRecipe transform

This topic tells you about the Application Accelerator OpenRewriteRecipe transform in Tanzu Application Platform (commonly known as TAP).

The OpenRewriteRecipe transform allows you to apply any Open Rewrite Recipe to a set of files and gather the results.

The engine leverages v8.7.4 of Open Rewrite and parses Java files using the grammar for Java 17.

The following Open Rewrite Recipes are supported:

Syntax reference

OpenRewriteRecipe(
  recipe: STRING,
  options: MAP,
  parseOrFail: BOOLEAN
)

Where:

  • recipe is the class name of the OpenRewrite recipe to use.
  • options is a map, in SpEL notation, used to configure the recipe.
  • (Optional) parseOrFail is a boolean that you can use to make the engine fail if OpenRewrite cannot parse the given input files according to the recipe used. For example, if you try to use a YAML recipe but a .java file is presented as input. The default is false.

Example

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 compared to non-fully qualified names, and so on.

engine {
  Include({"**/*.java"})
  OpenRewriteRecipe(
    recipe: 'org.openrewrite.java.ChangePackage',
    options: {
      oldPackageName: 'com.acme',
      newPackageName: #companyPkg
    }
  )
}

Diagram showing an OpenRewriteRecipe transform.

check-circle-line exclamation-circle-line close-line
Scroll to top icon