Ktor 3.0.1 Help

Creating the application distribution

The Ktor Gradle plugin automatically applies the Gradle Application plugin, which provides the ability to package applications, including code dependencies and generated start scripts. In this topic, we'll show you how to package and run a Ktor application.

Configure the Ktor plugin

To create the application distribution, you need to apply 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 "3.0.1" }
  2. Make sure the main application class is configured:

    application { mainClass.set("com.example.ApplicationKt") }

Package the application

The Application plugin provides various ways for packaging the application, for example, the installDist task installs the application with all runtime dependencies and start scripts. To create full distribution archives, you can use the distZip and distTar tasks.

In this topic, we'll use installDist:

  1. Open the terminal.

  2. Run the installDist task in one of the following ways depending on your operating system:

    ./gradlew installDist
    gradlew.bat installDist

    The Application plugin will create an image of the application in the build/install/<project_name> folder.

Run the application

To run the packaged application:

  1. Go to the build/install/<project_name>/bin folder in the terminal.

  2. Depending on your operating system, run the <project_name> or <project_name>.bat executable, for example:

    ./ktor-sample
    ktor-sample.bat
  3. Wait until the following message is shown:

    [main] INFO Application - Responding at http://0.0.0.0:8080

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

    Ktor app in a browser
Last modified: 30 April 2024