ktorio/ktor-build-plugins

Ktor Plugins for Build Systems

84

stars

294

commits

Kotlin

primary language

Sep 10, 2026

updated

README

Ktor Gradle plugin

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

  • Building fat JARs.
  • Dockerizing your applications.

Install the plugin

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

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

Requirements:

  • Gradle 8.11+
  • JVM 11+

EAP builds

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

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven("https://redirector.kotlinlang.org/maven/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:

  • buildImage: builds a project's Docker image to a tarball. This task generates a ***.tar file in the build directory. You can load this image to a Docker daemon using the docker load command.
  • runDocker: builds a project's image to a Docker daemon and runs it.
  • publishImageToLocalRegistry: builds and publishes a project's Docker image to a local registry.
  • publishImage: builds and publishes a project's Docker image to an external registry. Note that you need to configure the external registry using the ktor.docker.externalRegistry property for this task.

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

// build.gradle.kts
ktor {
    docker {
        jreVersion.set(JreVersion.JRE_21)
        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.

Contributors

renovate[bot]

106 commits

bjhham

53 commits

Stexxe

51 commits

jvmusin

36 commits

ktorio/ktor-build-plugins

Ktor Plugins for Build Systems

84

stars

294

commits

Kotlin

primary language

Sep 10, 2026

updated

README

Ktor Gradle plugin

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

  • Building fat JARs.
  • Dockerizing your applications.

Install the plugin

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

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

Requirements:

  • Gradle 8.11+
  • JVM 11+

EAP builds

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

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven("https://redirector.kotlinlang.org/maven/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:

  • buildImage: builds a project's Docker image to a tarball. This task generates a ***.tar file in the build directory. You can load this image to a Docker daemon using the docker load command.
  • runDocker: builds a project's image to a Docker daemon and runs it.
  • publishImageToLocalRegistry: builds and publishes a project's Docker image to a local registry.
  • publishImage: builds and publishes a project's Docker image to an external registry. Note that you need to configure the external registry using the ktor.docker.externalRegistry property for this task.

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

// build.gradle.kts
ktor {
    docker {
        jreVersion.set(JreVersion.JRE_21)
        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.

Contributors

renovate[bot]

106 commits

bjhham

53 commits

Stexxe

51 commits

jvmusin

36 commits

Languages

Kotlin

100.0%