What’s new with Quarkus 2.0 and how to get started quickly

Quarkus 2.0 has been released! In this article, we will cover the highlights of the new major version and the requirements to get started or migrate to this exciting new version.

Quarkus 2.0 aims to bring ease of development at an even higher level. There are several improvements in the tooling area and the major release of some core frameworks (namely Vert.x and Microprofile) have been both upgraded to their latest version. Let’s start with the requirements.

Quarkus 2.0 requires JDK 11 as a minimal version. Also, if you are compiling your applications to native code, GraalVM 21.1 is the recommended version for Quarkus 2.0.

You can grabe GraalVM 21.1 from here: https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-21.1.0

Major framework improvements

Quarkus uses Vert.x as a toolkit for build­ing re­ac­tive ap­pli­ca­tions on the JVM. Quarkus 2.0 is based on Vert.x 4 which ex­tends the Vert.x 3 line with a set of new fea­tures such as improved user experience, simpler handling of Future Callbacks, Microservices monitoring, high-performance re­ac­tive SQL clients, SQL templating, simple Web Session storage on an ex­ter­nal back­end. We will discuss more in detail Vert.x 4 in a separate tutorial.

The other core framework used by Quarkus is Microprofile, which now targets version 4 of the MicroProfile specifications.

All the SmallRye components in Quarkus have been updated to the latest and greatest and, apart from implementing MicroProfile 4, they also come with additional new features.

Quarkus CLI

So far, if you wanted to create Quarkus applications from the Command Line, the best option available for a quick bootstrap was using Quarkus Maven plugin. Now you can install Quarkus CLI for a simpler project creation/execution/testing. Quarkus CLI relies on JBang which is a scripting tool which allows running Java application with minimal setup, without the need of having a project configuration.

More about jbang here: JBang: Create Java scripts like a pro

You can install Quarkus CLI on Linux, macOS, and Windows (using a tool like like cygwin or mingw) as follows:

curl -Ls https://sh.jbang.dev | bash -s - app install --fresh --force quarkus@quarkusio

Once installed, the tool “quarkus” will be in your PATH. Open a new command line and try:

quarkus --help
Usage: quarkus [-ehv] [--verbose] [COMMAND]
  -e, --errors    Display error messages.
  -h, --help      Show this help message and exit.
  -v, --version   Print version information and exit.
      --verbose   Verbose mode.

Continuous Testing

Another outstanding feature of Quarkus 2.0 is Continuous Testing. This feature allows you to run (and customize) your tests in development mode on-demand, using a keyboard menu. The advantage is that you can go through application development, live reload and application tests without stopping your services. This will give you instant feedback on your changes, without the need to restart your environment every time. In the following example, we will show in practice how Continuous Testing works.

Creating a Quarkus 2.0 application with the CLI

Creating a Quarkus 2.0 application is just one line away. For example, let’s create one named “demo” with the following Maven coordinates:

$ quarkus create app --group-id com.sample --artifact-id demo --version 1.0
-----------

applying codestarts...
📚  java
🔨  maven
📦  quarkus
📝  config-properties
🔧  dockerfiles
🔧  maven-wrapper
🚀  resteasy-codestart

-----------
[SUCCESS] ✅  quarkus project has been successfully generated in:
--> /home/quarkus/demo

Fine, let’s see what we have got:

src
├── main
│   ├── docker
│   │   ├── Dockerfile.jvm
│   │   ├── Dockerfile.legacy-jar
│   │   ├── Dockerfile.native
│   │   └── Dockerfile.native-distroless
│   ├── java
│   │   └── com
│   │       └── sample
│   │           └── GreetingResource.java
│   └── resources
│       ├── application.properties
│       └── META-INF
│           └── resources
│               └── index.html
└── test
    └── java
        └── com
            └── sample
                ├── GreetingResourceTest.java
                └── NativeGreetingResourceIT.java

So, a Greeting application has been added, which uses a minimal development stack (CDI+REST and RESTAssured for testing). Here’s the Controller app:

package com.sample;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello RESTEasy";
    }
}

Now build your application with the “build” command:

$ quarkus build

Quarkus CLI can also run applications using the “dev” command:

$ quarkus dev

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.sample:demo >---------------------------
[INFO] Building demo 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- quarkus-maven-plugin:2.0.0.Final:dev (default-cli) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/francesco/quarkus/demo/target/classes
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/francesco/quarkus/demo/src/test/resources
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/francesco/quarkus/demo/target/test-classes
Listening for transport dt_socket at address: 5005
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2021-07-04 12:35:09,464 INFO  [io.quarkus] (Quarkus Main Thread) demo 1.0 on JVM (powered by Quarkus 2.0.0.Final) started in 1.535s. Listening on: http://localhost:8080
2021-07-04 12:35:09,479 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2021-07-04 12:35:09,479 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy, smallrye-context-propagation]

The only REST Endpoint is available through the “/hello” Path:

quarkus 2.0 tutorial getting started

Besides that, you can check at the bottom of the Quarkus log, the following log emitted by Continuous Testing:

--
Tests paused, press [r] to resume, [h] for more options>

So, you can, at any time, execute a round of tests on your services. For example, press “r” to run tests:

All 1 tests are passing (0 skipped), 1 tests were run in 2191ms. Tests completed at 12:35:34.
Press [r] to re-run, [v] to view full results, [p] to pause, [h] for more options>

Besides that, hitting “h” you can see all the available options to customize your tests:

The following commands are available:
[r] - Re-run all tests
[f] - Re-run failed tests
[b] - Toggle 'broken only' mode, where only failing tests are run (disabled)
[v] - Print failures from the last test run
[o] - Toggle test output (disabled)
[p] - Pause tests
[i] - Toggle instrumentation based reload (disabled)
[l] - Toggle live reload (enabled)
[s] - Force live reload scan
[h] - Display this help
[q] - Quit

Adding extensions through Quarkus CLI

The default application we have created included just a minimal set of extensions. You can add new extensions (using the CLI) in two ways. At first, you can add as an extra parameter the list of extensions. For example, suppose you wanted to add the health and kubernetes extensions:

$ quarkus create app --group-id com.sample --artifact-id demo --version 1.0 health kubernetes
selected extensions: 
- io.quarkus:quarkus-kubernetes
- io.quarkus:quarkus-smallrye-health

If you want to add extensions in an existing project, use the “ext add” command, followed by the extension list:

$ quarkus ext add kubernetes health

To know the list of available extensions, use the “ext list command:

$ quarkus ext add kubernetes health

To filter through the list, besides the good old grep, you can also use the “-s” command, combined with the “–concise” option which provides the artifact name of an extension:

$ quarkus ext list --concise -s vertx
Eclipse Vert.x                                     quarkus-vertx

References: https://quarkus.io/guides/cli-tooling

Found the article helpful? if so please follow us on Socials