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

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
  ...

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.

chain:
  - include: ["**/*.java"]
  - type: 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