Migrate to Quarkus 2 from Quarkus 1
In this guide we'll look at using OpenRewrite to perform an automated migration from Quarkus 1.x to Quarkus 2.x.

Example Configuration

The Quarkus1to2Migration recipe has no required configuration options and can be activated directly after taking a dependency on rewrite-quarkus in your build file:
Gradle
Maven
build.gradle
plugins {
id("org.openrewrite.rewrite") version("5.29.0")
}
rewrite {
activeRecipe("org.openrewrite.java.quarkus.quarkus2.Quarkus1to2Migration")
}
repositories {
mavenCentral()
}
dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:1.8.1"))
rewrite("org.openrewrite.recipe:rewrite-quarkus")
}
pom.xml
<project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-recipe-bom</artifactId>
<version>1.8.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.34.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.quarkus.quarkus2.Quarkus1to2Migration</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-quarkus</artifactId>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
At this point, you're ready to execute the migration by running mvn rewrite:run or gradlew rewriteRun. After running the migration you can inspect the results with git diff (or equivalent), manually fix anything that wasn't able to be migrated automatically, and commit the results.

Before and After

Here we highlight a small number of the larger set of refactoring operations Quarkus1to2Migration automates. For the full list of changes, see the recipe's reference documentation.

Migrate Deprecated Mutiny APIs

Deprecated Mutiny APIs (Before)
Deprecated Mutiny APIs (After)
package org.acme.demo.service;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.groups.MultiCollect;
import javax.enterprise.context.ApplicationScoped;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.Executor;
@ApplicationScoped
public class FactorService {
public static Uni<String> uniGreeting(String name) {
return Uni.createFrom().item(name)
.onItem()
.apply(n -> String.format("Factor this %s", n));
}
public static Multi<String> greetings(int count, String name) {
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
.onItem()
.transform(n -> String.format("hello %s - %d", name, n))
.transform()
.byTakingFirstItems(count);
}
public static Uni<List<String>> collectItems(int count, String name) {
Multi<String> multi = greetings(count, name);
Uni<List<String>> uni = multi
.collectItems()
.asList();
Executor e = command -> {
System.out.print("something");
};
multi.subscribeOn(e);
uni.subscribeOn(e);
return uni;
}
public static MultiCollect<Long> hotStreamGreetings(int count, String name) {
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
.transform()
.toHotStream()
.collectItems();
}
}
package org.acme.demo.service;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.groups.MultiCollect;
import javax.enterprise.context.ApplicationScoped;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.Executor;
@ApplicationScoped
public class FactorService {
public static Uni<String> uniGreeting(String name) {
return Uni.createFrom().item(name)
.onItem()
.transform(n -> String.format("Factor this %s", n));
}
public static Multi<String> greetings(int count, String name) {
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
.onItem()
.transform(n -> String.format("hello %s - %d", name, n))
.select()
.first(count);
}
public static Uni<List<String>> collectItems(int count, String name) {
Multi<String> multi = greetings(count, name);
Uni<List<String>> uni = multi
.collect()
.asList();
Executor e = command -> {
System.out.print("something");
};
multi.runSubscriptionOn(e);
uni.runSubscriptionOn(e);
return uni;
}
public static MultiCollect<Long> hotStreamGreetings(int count, String name) {
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
.toHotStream()
.collect();
}
}

Migrate io.quarkus.qute.api.*

io.quarkus.qute.api.* (Before)
io.quarkus.qute.api.* (After)
package org.acme.demo.misc;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.api.CheckedTemplate;
import io.quarkus.qute.api.ResourcePath;
import io.quarkus.scheduler.Scheduled;
public class ReportGenerator {
@ResourcePath("reports/v1/report_01")
Template report;
@Scheduled(cron = "0 30 * * * ?")
void generate() {
String result = report
.data("samples", new Object())
.render();
}
}
@CheckedTemplate
class HelloTemplate {
public static native TemplateInstance hello(String name);
}
package org.acme.demo.misc;
import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.Location;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.scheduler.Scheduled;
public class ReportGenerator {
@Location("reports/v1/report_01")
Template report;
@Scheduled(cron = "0 30 * * * ?")
void generate() {
String result = report
.data("samples", new Object())
.render();
}
}
@CheckedTemplate
class HelloTemplate {
public static native TemplateInstance hello(String name);
}

Migrate application.properties keys and values

application.properties (Before)
application.properties (After)
quarkus.dev.instrumentation=true
smallrye.jwt.sign.key-location=/keys/signing.pem
smallrye.jwt.encrypt.key-location=/keys/encrypt.pem
quarkus.quartz.force-start=true
quarkus.quartz.store-type=db
quarkus.neo4j.pool.metrics-enabled=true
# ...
# and other property keys/values as according to the Quarkus migration guide
quarkus.live-reload.instrumentation=true
smallrye.jwt.sign.key.location=/keys/signing.pem
smallrye.jwt.encrypt.key.location=/keys/encrypt.pem
quarkus.quartz.start-mode=forced
quarkus.quartz.store-type=jdbc-cmt
quarkus.neo4j.pool.metrics.enabled=true
# ...
# and other property keys/values as according to the Quarkus migration guide

Known Limitations

Unsupported Functionality
Issue
@ConfigProperties-annotated interfaces migrate to using @ConfigMapping, but not yet @ConfigProperties-annotated classes
#24
-
Export as PDF
Copy link
On this page
Example Configuration
Before and After
Migrate Deprecated Mutiny APIs
Migrate io.quarkus.qute.api.*
Migrate application.properties keys and values
Known Limitations