Ktor 3.5.2 Help

Native server

Ktor supports Kotlin/Native and allows you to run a server without an additional runtime or virtual machine. Currently, running a Ktor server under Kotlin/Native has the following limitations:

Add dependencies

Ktor server in a Kotlin/Native project requires at least two dependencies:

  • ktor-server-core (core dependency)

  • ktor-server-cio (the CIO engine)

The code snippet below shows how to add dependencies to the nativeMain source set in your build.gradle.kts file:

kotlin { sourceSets { nativeMain.dependencies { implementation("io.ktor:ktor-server-core:$ktor_version") implementation("io.ktor:ktor-server-cio:$ktor_version") } } }

To test a Native server, add the ktor-server-test-host artifact to the nativeTest source set:

kotlin { sourceSets { nativeTest.dependencies { implementation(kotlin("test")) implementation("io.ktor:ktor-server-test-host:$ktor_version") } } }

Configure native targets

Specify the required native targets and declare a native binary using the binaries property:

kotlin { val hostOs = System.getProperty("os.name") val arch = System.getProperty("os.arch") val nativeTarget = when { hostOs == "Mac OS X" && arch == "x86_64" -> macosX64("native") hostOs == "Mac OS X" && arch == "aarch64" -> macosArm64("native") hostOs == "Linux" && (arch == "x86_64" || arch == "amd64") -> linuxX64("native") hostOs == "Linux" && arch == "aarch64" -> linuxArm64("native") hostOs.startsWith("Windows") -> mingwX64("native") // Other supported targets are listed here: https://ktor.io/docs/server-native.html#targets else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } nativeTarget.apply { binaries { executable { entryPoint = "main" } } } }

Next steps

After configuring your Gradle build script, you can continue to create a Ktor server.

28 July 2026