Module 1: Recipe development environment and debugging
This module takes a deeper dive into the tools you'll use to author, run, and debug advanced OpenRewrite recipes. You'll explore the Moderne IntelliJ plugin's multi-repository search and recipe generation, then learn how to debug recipes using both IDE breakpoints and CLI runs.
This module assumes you have already completed Fundamentals Module 1: Recipe development environment. That module covers the environment setup this workshop depends on, including cloning the rewrite-recipe-starter repository, installing the Moderne plugin and CLI, and running the starter's tests. Complete it first if you haven't, then return here.
Exercise 1a: Using the Moderne plugin for IntelliJ
In this exercise, you'll use the Moderne IntelliJ plugin to search across repositories for an API, generate a recipe from it, and run that recipe via the plugin and the CLI.
Goals for this exercise
- Configure the Moderne plugin with repositories to search across.
- Perform a type-aware search across all of your local repositories.
- Create a simple search recipe.
- Run the recipe with the Moderne plugin and the CLI.
Steps
- You should already have the Moderne IntelliJ IDEA plugin installed from Fundamentals Module 1. (If not, install it now with the Moderne plugin installation guide.) Make sure the plugin has repositories to search across: either add a local root directory as a
Multi-repo, or select a Moderne organization (such asDefaultorNetflix) in theMulti-repossection. - Open any Java class in IntelliJ and look for an API that you're interested in searching for (e.g.,
System.out.println(..)orListUtils.map(..)). Then, follow the instructions in our multi-repository code search doc to look for that API across all of the repositories you added to the Moderne plugin. - Next, let's create a simple search recipe that finds that API you searched for. Right-click on the API again and select
Refactor > Create OpenRewrite Recipe.... Then select that you want to create aVisitor Stylerecipe.- For more details on creating recipes with the Moderne plugin, check out our how to create recipes guide.
- You should now have a scratch file that contains a simple recipe. Copy it over to the
rewrite-recipe-starterrepository and add it to thecom.yourorgpackage (or whatever you renamed your package to). - To run the recipe inside IntelliJ, click the gutter arrow next to the class declaration and select
Run <class_name>.

- The recipe runs against every repository you've configured in the plugin. Find code changes in the
Changestab and search results in theFindtab. - You can also run this recipe from the Moderne CLI using the Set Active Recipe +
mod run . --active-recipeworkflow you used in Fundamentals Module 1: right-click the class name, select Set Active Recipe, then runmod run . --active-recipefrom your workshop directory.
Takeaways
- The Moderne plugin allows you to search for APIs quickly and easily across numerous repositories.
- You can use the Moderne plugin to generate recipes based on an API you see.
Exercise 1b: Debugging recipes
In this exercise, you’ll learn how to debug recipes using both IDE breakpoints and command-line execution.
Goals for this exercise
- Debug recipes using the Moderne IntelliJ plugin.
- Understand how to set breakpoints in a recipe class or visitor.
- Use the
TreeVisitingPrinterto see what an LST looks like.
Steps
- Follow our guide for how to debug a recipe with the Moderne plugin. It walks you through setting an active recipe, building LSTs, and debugging the recipe — including how to attach a remote debugger from the CLI with
modw --debug run . --active-recipe. - Open a test case (e.g.,
FindSpringBeansTest), set breakpoints insidevisit()or the visitor logic, then run the test in debug mode (green bug icon in IntelliJ) and step through to inspect variables and visitor flow. - Configure the TreeVisitingPrinter to see what an LST looks like when your recipe finds a match — a great way to learn the different Java LST elements. You'll need to add
import org.openrewrite.java.TreeVisitingPrinter;to your recipe's imports.
Takeaways
- You can use the CLI in combination with the Moderne plugin to debug recipes.
- Logging and breakpoints are helpful tools for troubleshooting recipe behavior.
- The
TreeVisitingPrinteris a great way of understanding what the LST looks like.