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
1
plugins {
2
id("org.openrewrite.rewrite") version("5.12.0")
3
}
4
5
rewrite {
6
activeRecipe("org.openrewrite.java.quarkus.quarkus2.Quarkus1to2Migration")
7
}
8
9
repositories {
10
mavenCentral()
11
}
12
13
dependencies {
14
rewrite("org.openrewrite.recipe:rewrite-quarkus:0.9.0")
15
}
Copied!
pom.xml
1
<project>
2
<build>
3
<plugins>
4
<plugin>
5
<groupId>org.openrewrite.maven</groupId>
6
<artifactId>rewrite-maven-plugin</artifactId>
7
<version>4.13.0</version>
8
<configuration>
9
<activeRecipes>
10
<recipe>org.openrewrite.java.quarkus.quarkus2.Quarkus1to2Migration</recipe>
11
</activeRecipes>
12
</configuration>
13
<dependencies>
14
<dependency>
15
<groupId>org.openrewrite.recipe</groupId>
16
<artifactId>rewrite-quarkus</artifactId>
17
<version>0.9.0</version>
18
</dependency>
19
</dependencies>
20
</plugin>
21
</plugins>
22
</build>
23
</project>
Copied!
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)
1
package org.acme.demo.service;
2
3
import io.smallrye.mutiny.Multi;
4
import io.smallrye.mutiny.Uni;
5
import io.smallrye.mutiny.groups.MultiCollect;
6
7
import javax.enterprise.context.ApplicationScoped;
8
import java.time.Duration;
9
import java.util.List;
10
import java.util.concurrent.Executor;
11
12
@ApplicationScoped
13
public class FactorService {
14
15
public static Uni<String> uniGreeting(String name) {
16
return Uni.createFrom().item(name)
17
.onItem()
18
.apply(n -> String.format("Factor this %s", n));
19
}
20
21
public static Multi<String> greetings(int count, String name) {
22
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
23
.onItem()
24
.transform(n -> String.format("hello %s - %d", name, n))
25
.transform()
26
.byTakingFirstItems(count);
27
}
28
29
public static Uni<List<String>> collectItems(int count, String name) {
30
Multi<String> multi = greetings(count, name);
31
Uni<List<String>> uni = multi
32
.collectItems()
33
.asList();
34
Executor e = command -> {
35
System.out.print("something");
36
};
37
multi.subscribeOn(e);
38
uni.subscribeOn(e);
39
return uni;
40
}
41
42
public static MultiCollect<Long> hotStreamGreetings(int count, String name) {
43
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
44
.transform()
45
.toHotStream()
46
.collectItems();
47
}
48
}
Copied!
1
package org.acme.demo.service;
2
3
import io.smallrye.mutiny.Multi;
4
import io.smallrye.mutiny.Uni;
5
import io.smallrye.mutiny.groups.MultiCollect;
6
7
import javax.enterprise.context.ApplicationScoped;
8
import java.time.Duration;
9
import java.util.List;
10
import java.util.concurrent.Executor;
11
12
@ApplicationScoped
13
public class FactorService {
14
15
public static Uni<String> uniGreeting(String name) {
16
return Uni.createFrom().item(name)
17
.onItem()
18
.transform(n -> String.format("Factor this %s", n));
19
}
20
21
public static Multi<String> greetings(int count, String name) {
22
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
23
.onItem()
24
.transform(n -> String.format("hello %s - %d", name, n))
25
.select()
26
.first(count);
27
}
28
29
public static Uni<List<String>> collectItems(int count, String name) {
30
Multi<String> multi = greetings(count, name);
31
Uni<List<String>> uni = multi
32
.collect()
33
.asList();
34
Executor e = command -> {
35
System.out.print("something");
36
};
37
multi.runSubscriptionOn(e);
38
uni.runSubscriptionOn(e);
39
return uni;
40
}
41
42
public static MultiCollect<Long> hotStreamGreetings(int count, String name) {
43
return Multi.createFrom().ticks().every(Duration.ofMillis(1))
44
.toHotStream()
45
.collect();
46
}
47
}
Copied!

Migrate io.quarkus.qute.api.*

io.quarkus.qute.api.* (Before)
io.quarkus.qute.api.* (After)
1
package org.acme.demo.misc;
2
3
import io.quarkus.qute.Template;
4
import io.quarkus.qute.TemplateInstance;
5
import io.quarkus.qute.api.CheckedTemplate;
6
import io.quarkus.qute.api.ResourcePath;
7
import io.quarkus.scheduler.Scheduled;
8
9
public class ReportGenerator {
10
@ResourcePath("reports/v1/report_01")
11
Template report;
12
13
@Scheduled(cron = "0 30 * * * ?")
14
void generate() {
15
String result = report
16
.data("samples", new Object())
17
.render();
18
}
19
}
20
21
@CheckedTemplate
22
class HelloTemplate {
23
public static native TemplateInstance hello(String name);
24
}
Copied!
1
package org.acme.demo.misc;
2
3
import io.quarkus.qute.CheckedTemplate;
4
import io.quarkus.qute.Location;
5
import io.quarkus.qute.Template;
6
import io.quarkus.qute.TemplateInstance;
7
import io.quarkus.scheduler.Scheduled;
8
9
public class ReportGenerator {
10
@Location("reports/v1/report_01")
11
Template report;
12
13
@Scheduled(cron = "0 30 * * * ?")
14
void generate() {
15
String result = report
16
.data("samples", new Object())
17
.render();
18
}
19
}
20
21
@CheckedTemplate
22
class HelloTemplate {
23
public static native TemplateInstance hello(String name);
24
}
Copied!

Migrate application.properties keys and values

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

Known Limitations

Unsupported Functionality
Issue
@ConfigProperties-annotated interfaces migrate to using @ConfigMapping, but not yet @ConfigProperties-annotated classes
#24
-
Last modified 10d ago