1 of 57

Major migrations�made easy

Tim te Beek

2 of 57

Tim te Beek

Java Consultant

2

3 of 57

Major migrations�over the past decade

3

4 of 57

2009

��XML → Annotations

Component scanning

SOAP

Applets

4

2.5

5 of 57

2011

try ( Resource closeable = new Resource() ) { … }

List<String> diamonds = new ArrayList<>()

java.nio.file.Path

5

6 of 57

2014

(Integer x, Integer y) -> { return x + y; }

LocalDate releaseDate = LocalDate.of(2014, 3, 18);

6

7 of 57

2014 - Spring Boot 1.0

Jar not war

Opinionated

Non functionals

No XML

7

8 of 57

2015

Decomposition

Communication & failures

NoSQL

Kubernetes 1.0

8

9 of 57

2017

@BeforeEach, …

@Rule → Extension

@RunWith → @ExtendWith

assertThrows(Exception.class, () -> validate(invalidArgument))

9

10 of 57

2018

List.of()

var

HttpClient

java.xml.ws ❌

java.xml.bind ❌

10

11 of 57

2018 - Spring Boot 2.0

Java 7 ❌ Java 8+ ✅

Configuration Property Binding

WebFlux

Micrometer.io

Spring Data, Security, Cloud, Messaging, …

11

12 of 57

2019

GitHub buys Dependabot

WhiteSource buys Renovate

Increased awareness

❌ = 👩‍💻

✅ = 🤔

12

13 of 57

2021

Text blocks

record Point ( int x, int y ) { }

if ( object instanceof Integer i ) { }

return switch ( … ) { … };

--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED

13

14 of 57

2022

14

15 of 57

2022 - Spring Boot 3.0

Java 17 baseline

Jakarta EE 9

Kotlin 1.6

Groovy 4.0

Gradle 7.3

15

16 of 57

Change is the

only constant

16

17 of 57

OpenRewrite

17

18 of 57

Origin

Internal logging framework → SLF4J

Perfect transformation required

Abstract Syntax Tree parser & manipulation

Produce minimal changes

18

19 of 57

Broader application

Onboarding stalled

Struggle with outdated libraries & frameworks

Spring Boot 1.x → 2.x

JUnit 4 → JUnit 5

Apache license 2.0

19

20 of 57

Early focus on JVM

Search & transformation

Refactoring ecosystem

20

AssertJ

21 of 57

Abstract Syntax Tree

Type attribution

Format preservation

21

22 of 57

Recipes

Search & Refactor

Composition

22

23 of 57

Visitors

Match & modify elements

23

24 of 57

Modules

Search & Refactor

Composition

Specific purpose

Complete migrations

24

25 of 57

JUnit 5 recipe

type: specs.openrewrite.org/v1beta/recipe

name: org.openrewrite.java.testing.junit5.JUnit4to5Migration

recipeList:

- org.openrewrite.java.ChangeType:

oldFullyQualifiedTypeName: org.junit.Test

newFullyQualifiedTypeName: org.junit.jupiter.api.Test

- org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations

- org.openrewrite.java.testing.junit5.AssertToAssertions

- org.openrewrite.java.testing.junit5.StaticImports

- org.openrewrite.java.testing.junit5.ExpectedExceptionToAssertThrows

- …

25

26 of 57

JUnit 5 recipe

type: specs.openrewrite.org/v1beta/recipe

name: org.openrewrite.java.testing.junit5.JUnit4to5Migration

recipeList:

- org.openrewrite.java.ChangeType:

oldFullyQualifiedTypeName: org.junit.Test

newFullyQualifiedTypeName: org.junit.jupiter.api.Test

- org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations

- org.openrewrite.java.testing.junit5.AssertToAssertions

- org.openrewrite.java.testing.junit5.StaticImports

- org.openrewrite.java.testing.junit5.ExpectedExceptionToAssertThrows

-

26

27 of 57

Large migrations in small reusable steps

27

28 of 57

Running recipes

./mvnw org.openrewrite.maven:rewrite-maven-plugin:4.24.0:run� -Drewrite.recipeArtifactCoordinates=� org.openrewrite.recipe:rewrite-spring:4.21.0� -DactiveRecipes=� org.openrewrite.java.spring.boot2.SpringBoot1To2Migration

  1. Apply OpenRewrite plugin
  2. With Module dependency
  3. Run migration recipe

28

29 of 57

PetClinic Migration

Spring Boot 1.5.x → 2.x

Java 8 → Java 17

JUnit 4 → JUnit 5

29

30 of 57

Demo

30

31 of 57

Applications

OpenRewrite

Migrate

Fix

Enforce

31

32 of 57

Future

OpenRewrite

Kotlin

Java 17

Typescript

32

33 of 57

Spring Boot Migrator

33

34 of 57

“Spring Boot Migrator (SBM) aims to help developers�upgrade or migrate to Spring Boot by providing recipes for automated migrations.”

34

35 of 57

Origin

  • VMWare Labs project, Q4 2020
  • Switched from JavaParser to OpenRewrite
  • Jan 2021 Fabian Krüger full-time lead
  • March 2022 open-sourced under Spring-projects-experimental
  • Opinionated API for migrations to Spring Boot
  • Compatible with OpenRewrite recipes

35

36 of 57

Strong Spring focus

Java EE → Spring Boot

MuleSoft → Spring Integration

Upgrade Spring Boot

Adopt Spring Cloud

36

37 of 57

Inform & guide

With HTML report

37

38 of 57

Apply & iterate

Through interactive CLI

38

39 of 57

Future

Spring Boot Migrator

Spring Framework 6 & Boot 3

Introduce new Spring Module

Generate context related code

Contextual guidance

    • Performance
    • Cloud readiness
    • Native readiness

39

40 of 57

Moderne

40

41 of 57

Apply at scale

Committed to Open Source Recipes

41

42 of 57

app.moderne.io

42

43 of 57

Contribute to Open Source

Find project in need of ❤️

Reduce technical debt 👷

Keep review effort comparable 🔍

Report missing recipes 🐛

Finish Spring PetClinic migration 🐶

43

44 of 57

We could all use�more automation

44

45 of 57

Closing

45

46 of 57

Migrate safely,�quickly & in full

46

47 of 57

Where to learn more

docs.openrewrite.org

github.com/openrewrite

github.com/spring-projects-experimental/spring-boot-migrator

app.moderne.io

RewriteOSS.slack.com

47

48 of 57

48

49 of 57

Questions

49

50 of 57

Thank you!

50

51 of 57

51

52 of 57

52

53 of 57

53

54 of 57

54

55 of 57

55

56 of 57

56

57 of 57

57