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 hereWhen 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).
Functions
Close the URLClassLoader created over recipe JARs, freeing file descriptors and allowing the JAR files to be garbage-collected.
Build an OpenRewrite Environment from the given recipe JARs and optional rewrite.yaml. Returns the activated Recipe ready for execution.
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.