Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Migration Engineering with OpenRewrite

Avatar for Merlin Bögershausen Merlin Bögershausen
September 15, 2025
1

Migration Engineering with OpenRewrite

In recent years, development in the Java ecosystem has accelerated. Whether Java SE, Jakarta EE or Spring Boot - the releases and end-of-support messages are chasing each other. The number of necessary migrations is exploding and the feature pressure is not letting up.

With the open source tool OpenRewrite, migrations can be applied to projects in an automated and scalable way. The large and growing number of ready-made migrations offers solutions for many situations. Additional requirements can be implemented quickly thanks to the configuration and combinability of existing migrations. More complex adaptations are easy to implement thanks to the direct integration of Refaster templates.

This session covers the range of functions and the integration of OpenRewrite into existing projects. The basics of test-driven development of migrations will also be covered. Participants in this session will learn the basics of OpenRewrite and receive valuable tips for regular use.

Avatar for Merlin Bögershausen

Merlin Bögershausen

September 15, 2025
Tweet

Transcript

  1. 15

  2. 21 Declarative recipes Yaml Configurable Building blocks Composition Simple Refaster

    style recipes Annotated methods Compiler checked Limited applicability Straightforward replacements Starting point Imperative recipes Java visitors Full flexibility Increased complexity JavaTemplate builder Trait API Three types of recipes
  3. ©2024 Moderne, Inc. 22 100% accurate, style-preserving transformation because of

    a tech leap in code representation Characterized by serialization, type attribution, format preservation, and other metadata + another 600,000 nodes that didn’t fit in this graphic Text-based search Abstract Syntax Tree (AST) Lossless Semantic Tree (LST)
  4. ©2024 Moderne, Inc. 23 LST Example List.of("A", "B"); Identifier MethodCall

    Literal Literal Identifier Expression . (" "," ) { } ( ) I Ab Ab I Visitor Expression visitExpression(Expression e) MethodCall visitMethodCall(MethodCall m) Identifier visitIdentifier(Identifier i) Literal visitLiteral(Literal l)
  5. ©2024 Moderne, Inc. 24 Please let me see warnings ---

    type: specs.openrewrite.org/v1beta/recipe name:io.github.mboegers.RemoveDeprecationSuppression displayName: Remove SuppressWarnings for deprecation recipeList: - org.openrewrite.java.RemoveAnnotation: annotationPattern: \ '@java.lang.SuppressWarnings("deprecation")'
  6. ©2024 Moderne, Inc. 25 Replace a Method Invocation @RecipeDescriptor( name

    = "Replace oldOperation with betterOperation", description = "Replace deprecated ´oldOperation´ " + "with surrogate ´betterOperation´") public static class ReplaceOldOperation { @BeforeTemplate public void oldOperation(SomeService s) { s.oldOperation(); } @AfterTemplate public void newOperation(SomeService s) { s.betterOperation(); } }
  7. ©2024 Moderne, Inc. 26 Imperative Recipe API public class MakePublic

    extends Recipe { public String getDisplayName() { return "Make Class Public"; } @Override protected JavaVisitor<ExecutionContext> getVisitor() { return new ChangeTypeVisitor(); } private class MakePublicVisitor extends JavaVisitor<ExecutionContext> {/*..*/} } class JavaVisitor<P> extends TreeVisitor<J, P> { J visitStatement(Statement statement) {} J visitAnnotatedType(J.AnnotatedType annotatedType) {} J visitAnnotation(J.Annotation annotation) {} J visitAssert(J.Assert azzert) {} J visitAssignment(J.Assignment assign) {} J visitAssignmentOperation(J.AssignmentOperation assignOp) {} //... } Visit method for every Language Component Available
  8. ©2023 Moderne, Inc. 27 Growing ecosystem of modernization recipes Recipes

    programmatically execute automated search and transformation actions on a codebase. The ecosystem of OpenRewrite community-driven recipes is continually growing. Gradle Apache Maven Spring Quarkus Kubernetes Terraform Testcontainers AWS Micronaut Google Cloud Microsoft Azure Github Actions Concourse CircleCI Axon Framework Configuration Scripting Java-like Languages Frameworks, libraries, tooling CI/CD Infrastructure Python
  9. ©2024 Moderne, Inc. 28 Collaborating across the enterprise codebase Moderne

    DevCenter to always know the state of your code and take action. Code visualizations for understanding your code like never before. Code analysis and recipe recommendations Activity tracking and coordination Risk profile of vulnerabilities plus available fixes
  10. ©2024 Moderne, Inc. 30 Moderne scales OpenRewrite automation Single-repository mode

    Multi-repository mode OpenRewrite OSS Project Serialize LSTs to disk OpenRewrite Gradle Plugin OpenRewrite Maven Plugin Broadcom Application Advisor Amazon Q Code Transformation JetBrains OpenRewrite Plugin Microsoft VSCode Plugin Moderne Platform Moderne CLI Single- tenant SaaS On-prem Moderne proprietary IP Moderne DX Air-gapped service Shared OSS recipe ecosystem Codemods, linters, & other refactoring tech
  11. ©2024 Moderne, Inc. 31 Where to learn more docs.openrewrite.org moderne.ai

    app.moderne.io github.com/openrewrite youtube.com/@Moderne-and-OpenRewrite O’Reily Book: AI for Mass-Scale Code Refactoring and Analysis
  12. ©2024 Moderne, Inc. 32 Danke! Follow us! O’Reily Book: AI

    for Mass-Scale Code Refactoring and Analysis