Ktor 2.0.3 Help

Gradle Shadow plugin

The Gradle Shadow plugin allows you to create an executable JAR that includes all code dependencies (fat JAR).

Configure the Shadow plugin

To build a Fat JAR, you need to configure the Shadow plugin first:

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

    plugins { id("com.github.johnrengelman.shadow") version "7.1.2" }
  2. Make sure that the main application class is configured:

    application { mainClass.set("io.ktor.server.netty.EngineMain") }

Build a Fat JAR

To build a Fat JAR, open the terminal and execute the shadowJar task provided by the Shadow plugin.

./gradlew shadowJar
gradlew.bat shadowJar

When this build completes, you should see the ***-all.jar file in the build/libs directory. For example, for the fatjar project a file name is fatjar-all.jar.

Run the application

To run the built application:

  1. Go to the build/libs folder in a terminal.

  2. Execute the following command to run the application:

    java -jar fatjar-all.jar
  3. Wait until the following message is shown:

    [main] INFO Application - Responding at

    Open the link in a browser to see a running application:

    Ktor app in a browser
Last modified: 28 June 2022