RecipeLoader

Loads OpenRewrite recipes from recipe JARs and/or a rewrite.yaml declarative config.

Internally builds an OpenRewrite org.openrewrite.config.Environment that scans the provided JARs (and, when no JARs are given, the tool's own classpath) for recipes, styles, and categories. The load method returns the activated org.openrewrite.Recipe ready for execution by RecipeRunner.

URLClassLoader lifecycle

RecipeLoader implements AutoCloseable. When recipe JARs are supplied, load creates a URLClassLoader over those JARs but intentionally does not close it before returning — OpenRewrite visitor inner-classes are loaded lazily at org.openrewrite.Recipe.run time, and closing the loader beforehand causes NoClassDefFoundError.

Callers must close this RecipeLoader after recipe execution completes. Use try-with-resources (Java) or use {} (Kotlin):

RecipeLoader(logger).use { loader ->
val recipe = loader.load(recipeJars, recipeName, rewriteYaml)
recipe.run(sourceSet, ctx) // visitor classes loaded here
} // URLClassLoader closed here

When no recipe JARs are provided the thread context classloader is used and close is a no-op (the shared parent classloader must not be closed).

Constructors

Link copied to clipboard
constructor(logger: RunnerLogger)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun close()

Close the URLClassLoader created over recipe JARs, freeing file descriptors and allowing the JAR files to be garbage-collected.

Link copied to clipboard
fun load(recipeJars: List<Path>, activeRecipeName: String, rewriteYaml: Path?): Recipe

Build an OpenRewrite Environment from the given recipe JARs and optional rewrite.yaml. Returns the activated Recipe ready for execution.

fun load(recipeJars: List<Path>, activeRecipeName: String, rewriteYamlContent: String?): Recipe

Overload that accepts raw YAML content as a String instead of a file path. Use this when the rewrite.yaml content is already in memory and writing it to disk would be unnecessary I/O.