We want to:
-
- Add the Quarkus BOM and dependencies
-
- Replace the
@SpringBootApplicationannotation with@QuarkusMain
- Replace the
-
- Remove the statement
SpringApplication.run(AppApplication.class, args);
- Remove the statement
-
- Find the Java Class having as Annotation class:
@QuarkusMain - Check if the class includes a
public void static main()method - Find the
methodparameters (String[] args) to pass them to theQuarkus.run(); - Add the import package:
io.quarkus.runtime.Quarkus
- Find the Java Class having as Annotation class:
-
- Add a Java class implementing QuarkusApplication
Before We have the Spring Boot pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- // Step 0 -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
...and a @SpringBootApplication application class.
package com.todo.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication // Step 1
public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args); // Step 2
}
}After
Pom.xml updated
<!-- // Step 0 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-bom</artifactId>
<version>3.31.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
</dependencies>Quarkus.run() added to the Application
package com.todo.app;
import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.annotations.QuarkusMain;
@QuarkusMain // Step 1
public class AppApplication {
public static void main(String[] args) {
Quarkus.run(args); // Step 2 and 3
}
}and a new TodoApplication class acting as QuarkusMain entry point has been created
package com.todo.app;
// Step 4
public class TodoApplication implements QuarkusApplication {
@Override
public int run(String... args) throws Exception {
System.out.println("Hello user " + args[0]);
return 0;
}
}Steps: 0
- category: mandatory
customVariables: []
description: SpringBoot to Quarkus
effort: 1
labels:
- konveyor.io/source=springboot
- konveyor.io/target=quarkus
links: []
message: "SpringBoot to Quarkus."
ruleID: springboot-replace-bom-quarkus-0000
when:
java.referenced:
location: ANNOTATION
pattern: org.springframework.boot.autoconfigure.SpringBootApplication
order: 1 # New field to allow to sort the instructions to be executed
instructions: # New section containing the provider's instructions
ai:
- promptMessage: "Replace the SpringBoot parent dependency with Quarkus BOM within the pom.xml file"
manual:
- todo: "See openrewrite instructions"
openrewrite:
- name: Replace the SpringBoot parent dependency with Quarkus BOM within the pom.xml file
description: Replace the SpringBoot parent dependency with Quarkus BOM within the pom.xml file.
recipeList:
- org.openrewrite.maven.AddManagedDependency:
groupId: io.quarkus.platform
artifactId: quarkus-bom
version: 3.31.3
type: pom
scope: import
addToRootPom: false
- org.openrewrite.maven.AddDependency:
groupId: io.quarkus
artifactId: quarkus-core
version: 3.31.3
- org.openrewrite.maven.AddDependency:
groupId: io.quarkus
artifactId: quarkus-arc
version: 3.31.3
- org.openrewrite.maven.RemovePlugin:
groupId: org.springframework.boot
artifactId: spring-boot-maven-plugin
- spring.recipe.dev.snowdrop.mtool.openrewrite.AddQuarkusMavenPlugin
gav:
- dev.snowdrop.mtool:openrewrite-recipes:1.0.0-SNAPSHOT
- org.openrewrite:rewrite-maven:8.73.0Steps: 1, 2 and 3
- category: mandatory
customVariables: []
description: SpringBoot to Quarkus
effort: 1
labels:
- konveyor.io/source=springboot
- konveyor.io/target=quarkus
links: []
message: "SpringBoot to Quarkus."
ruleID: springboot-to-quarkus-00000
when:
java.referenced:
location: ANNOTATION
pattern: org.springframework.boot.autoconfigure.SpringBootApplication
order: 2
instructions:
ai:
- promptMessage: "SpringBoot to Quarkus"
manual:
- todo: "See openrewrite instructions"
openrewrite:
- name: SpringBoot to Quarkus
description: Move the SpringBootApplication annotation to QuarkusMain, Remove the statement SpringApplication.run(), Add the io.quarkus.runtime.Quarkus.run() method within the main void method and pass the String[] args as parameter"
preconditions:
- name: org.openrewrite.java.dependencies.search.ModuleHasDependency
groupIdPattern: org.springframework.boot
artifactIdPattern: spring-boot
version: '[3.5,)'
recipeList:
- spring.recipe.dev.snowdrop.mtool.openrewrite.ReplaceSpringBootApplicationWithQuarkusMainAnnotation
- org.openrewrite.java.RemoveMethodInvocations:
methodPattern: "org.springframework.boot.SpringApplication run(..)"
- spring.recipe.dev.snowdrop.mtool.openrewrite.AddQuarkusRun
gav:
- dev.snowdrop.mtool:openrewrite-recipes:1.0.0-SNAPSHOTStep 4
- category: mandatory
customVariables: []
description: SpringBoot to Quarkus
effort: 1
labels:
- konveyor.io/source=springboot
- konveyor.io/target=quarkus
links: []
message: "SpringBoot to Quarkus."
ruleID: springboot-add-class-quarkus-00000
when:
java.referenced:
location: ANNOTATION
pattern: org.springframework.boot.autoconfigure.SpringBootApplication
order: 3
instructions:
ai:
- promptMessage: "Add a Quarkus class"
manual:
- todo: "See openrewrite instructions"
openrewrite:
- name: Add a Quarkus class from class template"
description: Add a Quarkus class from class template
recipeList:
- spring.recipe.dev.snowdrop.mtool.openrewrite.CreateJavaClassFromTemplate:
className: "TodoApplication"
modifier: "public"
packageName: "com.todo.app"
sourceRoot: "src/main/java"
classTemplate: |
package %s;
import io.quarkus.runtime.QuarkusApplication;
%sclass %s implements QuarkusApplication {
@Override
public int run(String... args) throws Exception {
System.out.println("Hello user " + args[0]);
return 0;
}
}
gav:
- dev.snowdrop.mtool:openrewrite-recipes:1.0.0-SNAPSHOT