Ktor 1.5.4 Help


Restarting a server during development might take some time. Ktor allows you to overcome this limitation by using the Auto-reload feature, which reloads application classes on code changes and provides a fast feedback loop.

Enable Auto-reload

To use the Auto-reload feature, you need to enable the development mode first.

  • If you use EngineMain to run a server, enable development mode in the application.conf file.

  • If you run a server using embeddedServer, you can use the io.ktor.development system property.

When development mode is enabled, Ktor will be watching output files from the working directory automatically. If required, you can narrow down a set of watched folders by specifying watch paths.

Watch specific paths

When you enable development mode, Ktor starts watching output files from the working directory. For example, for a ktor-sample project build with Gradle the following folders will be watched:

ktor-sample/build/classes/kotlin/main/META-INF ktor-sample/build/classes/kotlin/main/com/example ktor-sample/build/classes/kotlin/main/com ktor-sample/build/classes/kotlin/main ktor-sample/build/resources/main

Watch paths allow you to narrow down a set of watched folders. To do this, you can specify a part of a watched path. For example, to monitor changes in the ktor-sample/build/classes subfolders, pass classes as a watch path. Depending on the way you use to run a server, you can specify a watch path in the following ways:

  • In the application.conf, specify the watch option:

    ktor { deployment { watch = [ classes ] } }

    You can specify several watch paths separated by a comma, for example:

    watch = [ classes, resources ]
  • If you are using embeddedServer, use the watchPaths parameter:

    embeddedServer( Netty, // ... watchPaths = listOf("classes") ).start(wait = true)

Recompile on changes

Since the Auto-reload feature detects changes in output files, you need to rebuild a project. You can do this manually in IntelliJ IDEA or enable continuous build execution in Gradle using the -t command-line option.

  • To rebuild a project manually in IntelliJ IDEA, select Build | Rebuild Project from the main menu.

  • To rebuild a project automatically using Gradle, you can run the build task with the -t option in a terminal:

    ./gradlew -t build

    In IntelliJ IDEA, you can create a dedicated run configuration for monitoring changes and pass -t to Arguments.

Last modified: 19 April 2021