Creating fat JARs using the Ktor Gradle plugin
The Ktor Gradle plugin allows you to create and run an executable JAR that includes all code dependencies (fat JAR).
Configure the Ktor plugin
To build a fat JAR, you need to configure the Ktor plugin first:
Open the
build.gradle.ktsfile and add the plugin to thepluginsblock:plugins { id("io.ktor.plugin") version "3.3.1" }Make sure the main application class is configured:
application { mainClass.set("com.example.ApplicationKt") }Optionally, you can configure the name of the fat JAR to be generated using the
ktor.fatJarextension:ktor { fatJar { archiveFileName.set("fat.jar") } }
Build and run a fat JAR
The Ktor plugin provides the following tasks for creating and running fat JARs:
buildFatJar: builds a combined JAR of a project and runtime dependencies. You should see the***-all.jarfile in thebuild/libsdirectory when this build completes.runFatJar: builds a fat JAR of a project and runs it.
27 June 2025