Moderne plugin for JetBrains IDEs
Moderne offers an IntelliJ IDEA plugin that can not only help you create and debug recipes, but can also assist with your general development experience by allowing you to easily search for code across all of your repositories at once.
Using the Moderne plugin
Goals
- Install and configure the Moderne IntelliJ IDEA plugin
- 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
- Debug your recipe, and use the
TreeVisitingPrinter
to see what the LST looks like
Steps
- If you haven't already installed the Moderne IntelliJ IDEA plugin, follow along with our Moderne plugin installation guide
- If you have many repositories checked out locally and want to search across those, please add the root directory as a
Multi-repo
. - If you don't have many repositories checked out locally or would prefer to see what it looks like to add a Moderne organization, please select one of the Moderne organizations (such as
Default
orNetflix
) in theMulti-repos
section. Note that if you selectDefault
, this is the sameDefault
group you used earlier in this workshop.
- If you have many repositories checked out locally and want to search across those, please add the root directory as a
- 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 Style
recipe.- 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-starter
repository you were using earlier and add it to thecom.yourorg
package. - There are two ways to run the recipe: from inside of IntelliJ or with the CLI. Let's start with running the recipe in IntelliJ against all of the repositories that you've specified in the Moderne plugin configuration.
- On the line where the class is defined, you should notice an arrow to the left of the text. Click it and then press
Run <class_name>
.

- The recipe will then begin running against all of the repositories you've specified. If any changes are made, you can find those in the
Changes
tab. If the recipe is a search recipe, you can find all search results in theFind
tab. - Next, let's try running the same recipe with the Moderne CLI. Right-click on the class name and select
Set Active Recipe
. - Open your terminal, navigate to your workshop directory, and run the recipe:
mod run . --active-recipe
. - You should see that this recipe ran and marked all the locations in all of the repositories that matched the API you generated the recipe from.
- Running the recipe is a great start, but it's always helpful to be able to debug the recipe. Follow our instructions for using the Moderne plugin to debug recipes.
- Another useful thing to do when debugging is to configure the TreeVisitingPrinter. This will really help you understand the different Java LST elements.
- Follow along with the instructions in that guide and make sure you can see what the LST looks like when it finds a match.
- Note: you'll need to add
import org.openrewrite.java.TreeVisitingPrinter;
to your import statements in your recipe.
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.
- You can use the CLI in combination with the Moderne plugin to debug recipes.
- The
TreeVisitingPrinter
is a great way of understanding what the LST looks like.