Using Quarkus With Vaadin

Quarkus is an open source, Kubernetes-native Java framework made for Java virtual machines and native compilation. It optimizes Java specifically for containers, enabling it to become an effective platform for serverless, cloud, and Kubernetes environments. See quarkus.io for more information about Quarkus.

Starting a Project

For starting a new project with Quarkus and Vaadin, you can get a project base for from Quarkus base starter. It is a project template with the necessary configuration and dependencies included for starting to build your own application.

This starter is also available with Gradle configuration in the Gradle branch.

Manual Setup

To be able to run your existing project with Quarkus, you need to have the vaadin-quarkus and vaadin-jandex Maven dependencies in the project, as well as configure the quarkus-maven-plugin.

For example:

<dependencyManagement>
    <dependencies>
        <!-- Quarkus Platform BOM to keep the project
             artifacts in synch with the quarkus.version -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-bom</artifactId>
            <version>${quarkus.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- Vaadin Platform BOM -->
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <type>pom</type>
            <scope>import</scope>
            <version>${vaadin.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- The Vaadin Quarkus extension -->
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-quarkus</artifactId>
        <!-- NOTE: this will come from vaadin-bom when final released -->
        <version>1.0.0.alpha1</version>
    </dependency>

    <!-- This jandex dependency contains Vaadin-core annotation indexes
         and is used as an offline reflection library. -->
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-core-jandex</artifactId>
    </dependency>

    <!-- Quarkus always pulls in slf4j-jboss-logmanager
         into target/lib; don't use slf4j-simple -->
    <dependency>
        <groupId>org.jboss.slf4j</groupId>
        <artifactId>slf4j-jboss-logmanager</artifactId>
        <version>1.1.0.Final</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!-- For indepth information on quarkus-maven-plugin
             see https://quarkus.io/guides/maven-tooling#build-tool-maven -->
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus.version}</version>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <goals>
                        <!-- Builds the Quarkus application -->
                        <goal>build</goal>
                        <!-- in these goals the Quarkus application bootstrap
                             is initialized and re-used in the build goal -->
                        <goal>generate-code</goal>
                        <goal>generate-code-tests</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Vaadin CDI Features

Quarkus’ dependency injection solution is based on CDI, so it is possible to use all CDI features.

See the documentation for Vaadin CDI features:

Vaadin Add-Ons in Quarkus Applications

Any Vaadin add-on used in a Quarkus application should contain a Jandex index. You can generate it using the jandex-maven-plugin. See How to Generate a Jandex Index.

If you cannot modify the dependency, you can still get Quarkus to index it by adding quarkus.index-dependency entries to your application.properties:

quarkus.index-dependency.<name>.group-id=
quarkus.index-dependency.<name>.artifact-id=
quarkus.index-dependency.<name>.classifier=(this one is optional)

The <name> string here is used to link the group-id, artifact-id and classifier entries in one logical block. It should be the same for those three entries and be any string literal.

Running the Application in Development Mode

After making Manual Setup steps, the Quarkus application can be started in development mode using the quarkus:dev goal in Maven.

mvn package quarkus:dev

The application is then available at localhost:8080 in the browser.

Running the Application in Production Mode

Quarkus base starter already includes the needed Maven configuration for running the application in production mode. If you use a project not based on the starter, it needs the configuration described in Deploying to Production.

Run the following commands to start the application:

mvn package -Pproduction
java -jar target/quarkus-app/quarkus-run.jar

Limitations

WebSockets Push does not currently work in the Vaadin extension for Quarkus. As a consequence, Live Reload functionality for changes in both Java and frontend files is not available.

Note
When running in development mode (quarkus:dev), changes in Java or frontend files compile after saving and can show up after refreshing the browser page.

Updated 2021-12-30