Home

Awesome

Ktor Gradle plugin

This plugin simplifies the deployment process of server Ktor applications and provides the following capabilities:

Install the plugin

To install the plugin, add it to the plugins block of your build script:

plugins {
    id("io.ktor.plugin") version "3.0.3"
}

Requirements:

EAP builds

You can also use EAP versions of the plugin published on Space Packages. To do this, consider adding https://maven.pkg.jetbrains.space/public/p/ktor/eap to the list of plugin repositories in the settings.gradle file, which may look like this:

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
    }
}

Build a fat JAR

To build and run a fat JAR, use the buildFatJar/runFatJar tasks. Note that a main class should be configured for your application, for example:

// build.gradle.kts
application {
    mainClass.set("com.example.ApplicationKt")
}

After the task is executed, you should see the ***-all.jar file in the build/libs directory. You can optionally configure the name of the fat JAR to be generated:

// build.gradle.kts
ktor {
    fatJar {
        archiveFileName.set("fat.jar")
    }
}

You can find a sample build script here: ktor-fatjar-sample/build.gradle.kts.

Dockerize your application

The following tasks are available for packaging, running, and deploying your application using Docker:

A sample configuration for Docker-related tasks might look as follows:

// build.gradle.kts
ktor {
    docker {
        jreVersion.set(JreVersion.JRE_17)
        localImageName.set("sample-docker-image")
        imageTag.set("0.0.1-preview")

        externalRegistry.set(
            DockerImageRegistry.dockerHub(
                appName = provider { "ktor-app" },
                username = providers.environmentVariable("DOCKER_HUB_USERNAME"),
                password = providers.environmentVariable("DOCKER_HUB_PASSWORD")
            )
        )
    }
}

You can find a sample build script here: ktor-docker-sample/build.gradle.kts.