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,
- QUARKUS + Hibernate CRUD example - Creating a CRUD REST API/Service
- Build REST CRUD APIs with Quarkus and MyBatis
- Create Quarkus Project With code.quarkus.io: Hello world example
- Quarkus - How to send email via SMTP - Quickstart
- Quarkus - Qute - Hello World Example
- Quarkus + Maven Hello World Example
- Configuring the HTTP Port on Quarkus Applications
- Quarkus - Interview questions and answers
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.
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.
- 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"
}
}
Open the browser and hit the endpoint http://localhost:8080/hello
More Quarkus Related topics,
- QUARKUS + Hibernate CRUD example - Creating a CRUD REST API/Service
- Build REST CRUD APIs with Quarkus and MyBatis
- Create Quarkus Project With code.quarkus.io: Hello world example
- Quarkus - How to send email via SMTP - Quickstart
- Quarkus - Qute - Hello World Example
- Quarkus + Maven Hello World Example
- Configuring the HTTP Port on Quarkus Applications
- Quarkus - Interview questions and answers