OpenRewrite: A Type-Aware Refactoring Engine for Repo-Scale Code Changes
Automated mass refactoring of source code. It consists of an auto-refactoring engine that runs prepackaged, open source refactoring recipes for common framework migrations, security fixes, and stylistic consistency tasks-reducing your coding effort from hours or days to minutes.
At a glance
- What is it?
- OpenRewrite is an open-source Java framework that runs prepackaged recipes for framework migrations, security fixes, and style consistency. It builds a type-aware Lossless Semantic Tree of your code, but it is single-repo by default and the core is Java-centric.
- Who is it for?
- Adopt OpenRewrite if you maintain Java or JVM-based repositories and need repeatable migrations, security patches, or style changes that you can run locally with Maven or Gradle. Do not adopt it if you expect out-of-the-box support for non-JVM languages without a Moderne license, or if you need to refactor thousands of repositories at once.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly Java, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 14, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
The Problem: Manual Mass Refactoring Is Slow and Error-Prone
When a framework releases a breaking change, or a security vulnerability affects a common API, developers face the same tedious edit across hundreds of files. Doing this by hand is slow, and a missed case can leave your build broken or your code vulnerable. OpenRewrite addresses this by turning refactoring into a repeatable, automated task. Instead of writing a one-off script that might not understand the syntax tree, you run a recipe that knows the exact structural changes needed. This is for teams that maintain codebases with frequent dependency upgrades, or for those who need to apply a consistent security fix across a whole repository. It is not a general-purpose code formatter; it is a structured migration tool.
The Mechanism: Lossless Semantic Trees and Recipes
OpenRewrite's core idea is the Lossless Semantic Tree (LST). The documentation describes it as a type-aware model of your source code, built in memory each time a recipe runs. Unlike a plain abstract syntax tree, the LST preserves the original formatting and comments, so after a recipe changes code, the output stays readable and diff-friendly. The engine parses source files into this tree, applies a recipe (a set of visitors that match and modify nodes), and then prints the tree back to text. This design allows recipes to be compositional: you can chain a migration recipe with a style recipe in a single run. The LST is also what enables type-aware search, because the tree carries semantic information about classes and methods, not just tokens.
Getting Started: Running a Recipe with Maven or Gradle
The README points to a quickstart guide, but the key entry points are the OpenRewrite Maven Plugin and the OpenRewrite Gradle Plugin. For a Maven project, you typically add the plugin to your build and specify a recipe in the configuration. A common command is `mvn org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.UpgradeJava17`. The exact syntax depends on your plugin version. For Gradle, you apply the plugin and use a task like `gradle rewriteRun` after configuring the active recipe. The plugins let you run one recipe at a time against a single repository, which is a deliberate constraint. You can also write your own recipes by extending the framework, but that requires understanding the LST API.
Language Support: Java First, Others with a Catch
OpenRewrite provides open-source parsers and base recipes for multiple languages: Java, Kotlin, Groovy, JavaScript/TypeScript, Python, and C#. That sounds broad, but the README is explicit: the Gradle and Maven plugins are for Java, and running recipes against the additional languages requires a Moderne license. The core framework is Java-centric, and the LST is built for Java's type system. If you work in a polyglot repository, you can use OpenRewrite for the Java parts, but you will need the commercial platform for the rest. This is a real limitation for teams hoping for a single tool to refactor all their code. The open-source recipes are also primarily Java-focused, so check the catalog before assuming your language is covered.
The Trade-Off: Single-Repo vs. Multi-Repo Scale
OpenRewrite itself is designed to refactor one repository at a time. The README states this directly. Moderne, the commercial platform built on OpenRewrite, runs the same recipes across hundreds or thousands of repositories at once. It achieves this by batch-building LSTs and serializing them, so they can be reused across repos without rebuilding. That is a different architecture: OpenRewrite rebuilds the LST in memory each time, which is fine for a single repo but becomes expensive at scale. If you are a large organization with many services, you will likely hit the ceiling of the open-source tool quickly. The multi-repo CLI from Moderne is the bridge, but it is part of the commercial offering. For a small team, the single-repo model is sufficient and keeps the tool simple.
Limitations and Failure Modes
The most obvious limitation is the licensing split. The core framework is Apache-2.0, but many recipes are not, and the README directs you to a licensing page to see which are open source. That means a recipe you need might require a commercial license. Another failure mode is recipe correctness: if a recipe does not match your exact framework version or code pattern, it may do nothing or, worse, change code incorrectly. The LST preserves formatting, but it does not guarantee that a recipe's logic is perfect. You should run recipes on a branch and review the diff. Also, because the LST is built in memory, very large repositories may consume significant memory and time. The documentation does not give performance numbers, so you should test on your own codebase. Finally, the single-repo constraint means you cannot easily apply a change across a monorepo with multiple independent projects in one run, unless you script it.
Alternatives: Codemods and Scripted Refactoring
The closest alternative is a codemod tool like jscodeshift, which is popular in the JavaScript ecosystem. jscodeshift uses ASTs to apply transformations, but it is not type-aware by default and does not preserve formatting as faithfully as OpenRewrite's LST. Another alternative is to write your own scripts with a parser library like ANTLR or JavaParser, but that requires building the semantic analysis yourself. OpenRewrite's advantage is that it ships with a catalog of tested recipes, so you do not have to write the logic from scratch. The trade-off is that OpenRewrite is tied to its own model and recipe API, whereas a script is more flexible but more error-prone. If you only need a one-off change, a script might be faster to write, but for ongoing migrations, the recipe catalog saves time.
Maintenance and Upgrade Cost
OpenRewrite is actively maintained, with multiple releases per week in August 2026 (v8.91.0, v8.91.1, v8.91.2). This means you will need to keep your plugin version up to date to get new recipes and bug fixes. The framework itself is stable, but recipes change as frameworks evolve. Upgrading the plugin is usually a matter of changing a version number, but you should test after each upgrade because recipe behavior may change. The license is Apache-2.0 for the core, which is permissive, but you must check each recipe's license individually. The README does not mention a migration guide for plugin upgrades, so you will rely on release notes. Given the release cadence, plan for periodic updates, but the cost is low if you only use a few recipes.
Editorial conclusion
Adopt OpenRewrite if you maintain Java or JVM-based repositories and need repeatable migrations, security patches, or style changes that you can run locally with Maven or Gradle. Do not adopt it if you expect out-of-the-box support for non-JVM languages without a Moderne license, or if you need to refactor thousands of repositories at once. Before committing, verify that the recipe catalog covers your exact framework versions and that your build system is supported. Check the licensing page to confirm which recipes are Apache-2.0 versus commercially licensed, and test a recipe on a branch before applying it broadly.
Community notes