Kotlin + Quarkus - Hello world example

Hello everyone, Today we will learn how how to create a Kotlin + Quarkus hello world application.

More Quarkus Related topics,


Create Quarkus Project With code.quarkus.io

Launch Quarkus Initializr using https://code.quarkus.io/ link
Specify Project Details 


Look at the above diagram, we have specified the following details:
  • Build Tool: Gradle with Kotlin
  • Group: org.knf.dev.demo
  • Artifact: kotlin-quarkus-helloworld
  • Search & Pick extensions: RESTEasy JSON-B
Once, all the details are entered, click on Generate your application button will generate a Quarkus project and downloads it. Next, Unzip the downloaded zip file and import it into your favorite IDE.


Import project in your favorite IDE.I am using IntelliJ IDEA.Gradle would take some time to download all the dependencies and initialize the project.

Project Directory:

Download the project source code and review the project folder structure :

Gradle Build:

Review the build.gradle.kts file, this should be self-explanatory.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
id("io.quarkus")
kotlin("jvm") version "1.5.31"
}

repositories {
mavenCentral()
mavenLocal()
}

val quarkusPlatformGroupId: String by project
val quarkusPlatformArtifactId: String by project
val quarkusPlatformVersion: String by project

dependencies {
implementation(enforcedPlatform(
"${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
implementation("io.quarkus:quarkus-arc")
implementation("io.quarkus:quarkus-resteasy-jsonb")
testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")
implementation(kotlin("stdlib-jdk8"))
}

group = "com.knf.dev.demo"
version = "1.0.0-SNAPSHOT"

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.add("-parameters")
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "11"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "11"
}

The Quarkus core Technologies:
  • Quarkus uses RESTEasy for the JAX-RS endpoint. 
  • Quarkus uses Vert.x and Netty at its core, providing reactive and non-blocking HTTP layer. 
  • Quarkus uses JBoss Log Manager as the default logging framework. 
  • Quartus utilizes a modified version of Undertow  that runs on top of Vert.x 
  • Quarkus uses SmallRye Config, implementation of Eclipse MicroProfile Config, for configuration data.
For testing:
  • Quarkus uses JUnit 5 for testing. 
  • Quarkus uses rest-assured to test HTTP endpoints.

Quarkus JAX-RX endpoint

package com.knf.dev.demo

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

@Path("/hello")
class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
fun hello(): String {
return "Hello World"
}
}

Run

Build application jar file: gradle build


Start application: java -jar quarkus-run.jar

Open the browser and hit the endpoint http://localhost:8080/hello


Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Spring Boot + Mockito simple application with 100% code coverage

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete