Kest

Search

Search the documentation

Introduction

Start with Gradle

Create a Kest application by hand with a normal Gradle build, in Kotlin or in Java.

You do not need the kest tool. A Kest application is an ordinary Gradle project with three extra lines: the KSP plugin and the processor (which does the wiring at build time) and the Kest dependencies. This page builds one from an empty folder, in Kotlin and in Java.

You need JDK 21 and Gradle (brew install gradle, or use a project's ./gradlew). Run gradle --version to check.

Where the Kest packages come from

Kest packages are published to GitHub Packages (Maven). GitHub requires a token even to read them: create a personal access token (classic) with the read:packages scope, and put it in ~/.gradle/gradle.properties (not in your project). Prereleases come from the dev branch (0.4.0-dev.1); stable versions come from prod. JitPack also builds tags, once the repository is public:

gpr.user=your-github-username
gpr.token=ghp_yourtoken

Or, to try Kest without a token, publish it to your own machine from a checkout: ./gradlew publishToMavenLocal in the Kest repository, then use mavenLocal() below.

Kotlin

demo/
  settings.gradle.kts
  gradle.properties
  build.gradle.kts
  src/main/kotlin/demo/Main.kt
settings.gradle.kts
rootProject.name = "demo"
gradle.properties
ksp.useKSP2=true
build.gradle.kts
plugins {
    kotlin("jvm") version "2.3.21"
    id("com.google.devtools.ksp") version "2.3.13"     // runs the Kest processor while compiling
    application
}
 
repositories {
    mavenCentral()
    mavenLocal()                                       // only if you published Kest locally
    maven {
        url = uri("https://maven.pkg.github.com/jamie-codez/kest")
        credentials {
            username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
            password = providers.gradleProperty("gpr.token").orNull ?: System.getenv("GITHUB_TOKEN")
        }
    }
}
 
kotlin { jvmToolchain(21) }
 
dependencies {
    implementation(platform("io.kest.framework:bom:0.4.0"))     // one version for every Kest package: use the latest release
    implementation("io.kest.framework:core")
    implementation("io.kest.framework:http-server")
    implementation("io.kest.framework:http-server-netty")        // the web server engine
    implementation("io.kest.framework:json-jackson")             // JSON
    implementation("io.kest.framework:validation")
    ksp(platform("io.kest.framework:bom:0.4.0"))        // the BOM must be applied to ksp too
    ksp("io.kest.framework:processor")                           // once; it serves every package
    testImplementation(kotlin("test"))
    testImplementation("io.kest.framework:testing")
}
 
application { mainClass.set("demo.MainKt") }
tasks.test { useJUnitPlatform() }
src/main/kotlin/demo/Main.kt
package demo
 
@Controller("/")
class HelloController {
    @Get fun hello(@Query name: String?): Map<String, String> = mapOf("message" to "Hello, ${name ?: "world"}!")
}
 
@Module(imports = [JacksonJsonModule::class], controllers = [HelloController::class])
class AppModule
 
fun main(args: Array<String>) {
    val app = Kest.run<AppModule>(args)
    app.http(NettyHttpAdapter(port = 8080))
    Thread.currentThread().join()
}

(Add the imports your editor suggests: io.kest.core.*, io.kest.http.*, io.kest.http.netty.NettyHttpAdapter, io.kest.json.jackson.JacksonJsonModule.)

gradle wrapper            # once: creates ./gradlew
./gradlew run
curl "localhost:8080/?name=Ann"        # {"message":"Hello, Ann!"}

Java

A Java application uses the same build, because the processor is a KSP plugin and KSP is run by the Kotlin Gradle plugin (which also reads your .java files). You write no Kotlin: the plugin is only there to host the processor.

demo/
  settings.gradle.kts   gradle.properties   build.gradle.kts
  src/main/java/demo/Application.java   HelloController.java   AppModule.java
build.gradle.kts
plugins {
    kotlin("jvm") version "2.3.21"                        // only to host KSP
    id("com.google.devtools.ksp") version "2.3.13"
    application
}
repositories { mavenCentral(); mavenLocal() /* + the GitHub Packages block above */ }
java { toolchain { languageVersion.set(JavaLanguageVersion.of(21)) } }
kotlin { jvmToolchain(21) }
 
dependencies {
    implementation(platform("io.kest.framework:bom:0.4.0"))
    implementation("io.kest.framework:core")
    implementation("io.kest.framework:http-server")
    implementation("io.kest.framework:http-server-netty")
    implementation("io.kest.framework:json-jackson")
    ksp(platform("io.kest.framework:bom:0.4.0"))        // the BOM must be applied to ksp too
    ksp("io.kest.framework:processor")
}
application { mainClass.set("demo.Application") }
HelloController.java
package demo;
 
import io.kest.core.Controller;
import io.kest.http.Get;
import io.kest.http.Query;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
 
@Controller("/")
public class HelloController {
    @Get
    public Map<String, String> hello(@Query("name") @Nullable String name) {      // name the parameter (Java does not keep names); @Nullable makes it optional
        return Map.of("message", "Hello, " + (name == null ? "world" : name) + "!");
    }
}
AppModule.java
package demo;
 
import io.kest.core.Module;
import io.kest.json.jackson.JacksonJsonModule;
 
@Module(imports = {JacksonJsonModule.class}, controllers = {HelloController.class})
public class AppModule { }
Application.java
package demo;
 
import io.kest.core.Container;
import io.kest.core.Kest;
import io.kest.http.KestHttp;
import io.kest.http.netty.NettyHttpAdapter;
 
public class Application {
    public static void main(String[] args) throws InterruptedException {
        Container app = Kest.run(AppModule.class, o -> { });                       // build the container
        KestHttp.start(app, new NettyHttpAdapter(8080), http -> { });              // start the web server
        Thread.currentThread().join();
    }
}

A complete, tested Java application (database, validation, guards) is examples/java-api: see Using Kest from Java.

If the build fails

MessageMeaning
Could not resolve io.kest.framework:...the repository block or token is missing; check gpr.user and gpr.token, or mavenLocal()
'X' is listed in 'controllers' but is not annotated...a class is in a module list but has no Kest annotation
KSP or Kotlin errors straight awayJAVA_HOME is not JDK 21

Maven is not supported yet (planned, next). Scala, Groovy and Clojure work now: see JVM languages.

Read more