Skip to main content

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

This recipe has no required configuration options. It can be activated by adding a dependency on `org.openrewrite.recipe:rewrite-quarkus` in your build file or by running a shell command (in which case no build changes are needed):

  1. Add the following to your build.gradle file:
    build.gradle
    plugins {
    id("org.openrewrite.rewrite") version("latest.release")
    }

    rewrite {
    activeRecipe("org.openrewrite.quarkus.quarkus2.Quarkus1to2Migration")
    }

    repositories {
    mavenCentral()
    }

    dependencies {
    rewrite("org.openrewrite.recipe:rewrite-quarkus:2.33.0")
    }
  2. Run gradle rewriteRun to run the recipe.

For the full list of changes this recipe will make, see the recipe reference page.

Once you've configured your project, 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

Migrate Deprecated Mutiny APIs

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();
}
}

Migrate io.quarkus.qute.api.*

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);
}

Migrate application.properties keys and values

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

Known Limitations

Unsupported FunctionalityIssue
@ConfigProperties-annotated interfaces migrate to using @ConfigMapping, but not yet @ConfigProperties-annotated classes#24
Kubernetes Client 5.4-
Vert.x 4.0-

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.