Ktor 2.3.9 Help

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:

  1. Open the build.gradle.kts file and add the plugin to the plugins block:

    plugins { id("io.ktor.plugin") version "2.3.9" }
  2. Make sure the main application class is configured:

    application { mainClass.set("com.example.ApplicationKt") }
  3. 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 the build/libs directory when this build completes.

  • runFatJar: builds a fat JAR of a project and runs it.

Last modified: 02 November 2022