RewriteRunner
Programmatic entry point for running OpenRewrite recipes from library code.
Encapsulates the same orchestration pipeline that the CLI uses:
Load ToolConfig (from Builder.configFile if supplied, otherwise defaults).
Resolve recipe JARs from Maven coordinates via RecipeArtifactResolver.
Load the requested recipe via RecipeLoader.
Build the Lossless Semantic Tree (LST) for the project via LstBuilder.
Execute the recipe via RecipeRunner.
Optionally write changed files to disk (controlled by Builder.dryRun).
Obtain an instance through the Builder:
val runner = RewriteRunner.builder()
.projectDir(Paths.get("/path/to/project"))
.activeRecipe("org.openrewrite.java.format.AutoFormat")
.build()
val result = runner.run()Content copied to clipboard
Java usage:
RunResult result = RewriteRunner.builder()
.projectDir(Paths.get("/path/to/project"))
.activeRecipe("org.openrewrite.java.format.AutoFormat")
.build()
.run();Content copied to clipboard
This class is thread-safe for concurrent run calls only when each call operates on a different Builder.projectDir. Sharing the same project directory across concurrent runs is not supported.