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

JUG Saxony Day 2023: Upgrade to Spring Boot 3? ...

JUG Saxony Day 2023: Upgrade to Spring Boot 3? Spring Tools to the Rescue!

Martin Lippert

October 12, 2023
Tweet

More Decks by Martin Lippert

Other Decks in Programming

Transcript

  1. Martin Lippert, @martinlippert September 2023 Upgrade to Spring Boot 3?

    Spring Tools to the Rescue Copyright © 2022 VMware, Inc. or its affiliates.
  2. New Spring Boot releases all the time • Many patch

    releases all the time • New minor release every 6 month, sometimes new major releases • It is super important to stay up-to-date • But it is sometimes hard to always stay up-to-date Where are we?
  3. Release Notes + Migration Guides • You have to read

    everything carefully • You need to find out what needs to be changed for your project • You need to apply all those changes manually How to upgrade?
  4. Let the user know • Automatically check the versions that

    you use • Show information about new versions and support ranges Help the user to upgrade • Migration guides written in “code” • Looks at your project and applies necessary changes - AUTOMATICALLY • Some limitations apply What is new to Spring Tools?
  5. No silver bullet • The tools apply many changes, but

    not all of them • The goal is to automate as much as possible • There is no guarantee that you are done with the upgrade afterwards - probably additional manual steps needed ◦ But this will improve with every tools release - of course… 😉 Limitations
  6. Looking for feedback Reminder: Everything that you will see is

    early days • We are looking for feedback and suggestions • If you want to get involved here, let us know
  7. What is OpenRewrite? • “Open-source, semantic type aware search and

    transformation framework.” • “OpenRewrite enables large-scale distributed source code refactoring for framework migrations, vulnerability patches, and API migrations” • Automatically transform source code (for various purposes) • https://docs.openrewrite.org/ • https://github.com/openrewrite Based on initial work at Netflix to keep source code up-to-date. Sponsored now by Moderne.io. The Moderne SaaS allows organizations to run search and transformations across hundreds of repositories (millions of lines of code) simultaneously and offer a free service for the OSS community at https://public.moderne.io/ Under the hood
  8. What can OpenRewrite be used for? • Patching CVEs •

    Migrate from Java 8 to Java 11 to Java 17… • Migrate between framework versions • Automatically adapt code to changed APIs • … • Works across various source file types (like Java Source Code, property files, YAML, other languages, etc.) Purpose
  9. How does OpenRewrite work internally? • Step 1: Parse source

    files into AST ◦ Type resolution ◦ Keep formatting intact • Step 2: Run visitors on ASTs to transform them ◦ Visitors contain the logic what exactly to do for the refactoring, the migration, the code fix, etc. • Step 3: Generate source changes The internals
  10. Recipes aggregate visitors • Users deal with recipes ◦ The

    AST visitors are an implementation detail • Recipes are either ◦ defined using YAML, or ◦ implemented in Java Recipes
  11. Recipes can be written by anyone • OpenRewrite comes with

    a huge set of basic transformation recipes pre-packaged and ready-to-use ◦ https://docs.openrewrite.org/reference/recipes • It is easy to use them and write custom recipes • Community around recipes • Packages could bring their own recipes ◦ E.g. a library contains recipes to migrate client code to a new version of the library The power behind it
  12. Transforming the code Running recipes via Maven or Gradle •

    ./mvnw rewrite:discover - Lists all the available recipes • ./mvnw rewrite:run - Runs the recipes configured as active (in the build config) • ./mvnw rewrite:dryRun - Runs the recipes, but creates a patch file instead of changing the files directly
  13. What we do inside the Spring Tools List and run

    recipes from the UI • Show the recipes that are available • Let the user select the recipes • Execute the recipes within the IDE
  14. Authoring recipes You can write your own recipes and try

    them • A preference allows you to add your own recipes to the language server • Write them in one workspace, test them in another • No need to restart the IDE, just press “Refresh”
  15. Another use case Validations and Quick Fixes • Let’s now

    push this beyond running recipes on projects • Let’s combine this with validations/markers and code actions/quick fixes • This goes beyond what OpenRewrite supports out-of-the-box, but it can be added on top
  16. Validations and Quick Fixes Something that looks like this validation

    code action / quick fix (implemented as a recipe)
  17. OpenRewrite • https://docs.openrewrite.org/ • https://github.com/openrewrite IDE Integration • Started as

    part of the Spring Tools: https://github.com/spring-projects/sts4/ • Independent of Spring Tooling in the future? • Contact us on Twitter: http://twitter.com/springtools4/ Resources
  18. Thank you @martinlippert © 2022 Spring. A VMware-backed project. (special

    thanks to Tyler van Gorder and Alex Boyko for their support and work on this)