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.kts
file and add the plugin to theplugins
block:plugins { id("io.ktor.plugin") version "3.0.0-beta-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.fatJar
extension: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.jar
file in thebuild/libs
directory when this build completes.runFatJar
: builds a fat JAR of a project and runs it.
Last modified: 30 April 2024