RewriteRunner

Programmatic entry point for running OpenRewrite recipes from library code.

Encapsulates the same orchestration pipeline that the CLI uses:

  1. Load ToolConfig (from Builder.configFile if supplied, otherwise defaults).

  2. Resolve recipe JARs from Maven coordinates via RecipeArtifactResolver.

  3. Load the requested recipe via RecipeLoader.

  4. Build the Lossless Semantic Tree (LST) for the project via LstBuilder.

  5. Execute the recipe via RecipeRunner.

  6. 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()

Java usage:

RunResult result = RewriteRunner.builder()
.projectDir(Paths.get("/path/to/project"))
.activeRecipe("org.openrewrite.java.format.AutoFormat")
.build()
.run();

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.

Types

Link copied to clipboard
class Builder

Builder for RewriteRunner.

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun run(): RunResult

Execute the configured recipe against the project directory.