Using OpenRewrite recipes
|
Important
|
OpenRewrite recipe support is provided as Technology Preview only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs), might not be functionally complete, and Red Hat does not recommend to use them for production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. See Technology Preview features support scope on the Red Hat Customer Portal for information about the support scope for Technology Preview features. |
You can refactor the source code of Java applications by using OpenRewrite recipes with the {ProductShortName} CLI.
For example, the OpenRewrite recipe org.jboss.windup.JavaxToJakarta renames imported javax packages to their jakarta equivalents.
-
Run
{mta-cli}, specifying the recipe name, the path to the configuration file, and the application:$ ./{mta-cli} transform openrewrite --input </path/to/source/project> \ "-Drewrite.configLocation=<path/to/rewrite.yaml>" \ "-DactiveRecipes=<recipe_name>" --goal dryRun-
"-DactiveRecipes=<recipe name>": Specify the OpenRewrite recipe, for example,org.jboss.windup.JavaxToJakarta. -
--input: Specify the application to be refactored. The application must be the top of the source code project containing a Maven Project Object Model (POM) XML file,pom.xml. -
-Drewrite.configLocation=<path/to/rewrite.yaml>: The location of therewrite.yamlconfiguration file to use. The shippedrewrite.yamlconfiguration files are located in your<{ProductShortName}_HOME>/rules/openrewritesubfolder, for example," -Drewrite.configLocation=<{ProductShortName}_HOME>/rules/openrewrite/jakarta/javax/imports/rewrite.yaml". -
"-DactiveRecipes=<recipe name>": Specify the OpenRewrite recipe, for example,org.jboss.windup.JavaxToJakarta.You can include more than one recipe by specifying each in the
activeRecipesparameter. For example, to include the recipesorg.jboss.windup.JavaxInjectToJakartaInjectandorg.jboss.windup.JavaxEjbToJakartaEjb", enter the following for"-DactiveRecipes=<recipe name>":"-DactiveRecipes=org.jboss.windup.JavaxInjectToJakartaInject, \ org.jboss.windup.JavaxEjbToJakartaEjb" -
--goal: Optional: The OpenRewrite Maven goal to run.-
dryRun: The script returns a list of proposed changes. Ignore the"Run 'mvn rewrite:run' to apply the recipes"message. -
run: The script applies the changes.
-
-
-
Run
{mta-cli}with--goal runto apply the recipe:$ ./{mta-cli} transform openrewrite --input </path/to/source/project> \ "-Drewrite.configLocation=<path/to/rewrite.yaml>" \ "-DactiveRecipes=<recipe_name>" --goal run