From 34b88846653841a5cdd1618704b9d2897a43c78e Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Mon, 28 Oct 2024 22:22:13 +0000 Subject: [PATCH] Update to Ktor 3.0 --- README.md | 2 +- build.gradle.kts | 18 +++++++++--------- src/main/kotlin/Main.kt | 7 +++---- src/main/kotlin/web/IndexResource.kt | 1 - src/main/kotlin/web/WidgetResource.kt | 1 - src/test/kotlin/common/ServerTest.kt | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d9874f8..2bbfdf4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Starter project to create a simple RESTful web service in Kotlin -**Updated for Kotlin 2.0.0 and Ktor 2.3.12** +**Updated for Kotlin 2.0.21 and Ktor 3.0.0** Companion article: diff --git a/build.gradle.kts b/build.gradle.kts index 54de03e..926498a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,16 @@ -val ktorVersion = "2.3.12" -val exposedVersion = "0.52.0" -val h2Version = "2.2.224" +val ktorVersion = "3.0.0" +val exposedVersion = "0.55.0" +val h2Version = "2.3.232" val hikariCpVersion = "5.1.0" -val flywayVersion = "10.11.0" -val logbackVersion = "1.5.6" +val flywayVersion = "10.20.1" +val logbackVersion = "1.5.12" val assertjVersion = "3.26.3" -val restAssuredVersion = "5.4.0" -val junitVersion = "5.10.1" +val restAssuredVersion = "5.5.0" +val junitVersion = "5.11.3" plugins { - kotlin("jvm") version "2.0.0" - kotlin("plugin.serialization") version "2.0.0" + kotlin("jvm") version "2.0.21" + kotlin("plugin.serialization") version "2.0.21" id("org.jetbrains.kotlinx.kover") version "0.8.2" application } diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index ef3cac9..10510df 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,9 +1,8 @@ import io.ktor.serialization.kotlinx.* import io.ktor.serialization.kotlinx.json.* import io.ktor.server.application.* -import io.ktor.server.engine.* import io.ktor.server.netty.* -import io.ktor.server.plugins.callloging.* +import io.ktor.server.plugins.calllogging.* import io.ktor.server.plugins.contentnegotiation.* import io.ktor.server.plugins.defaultheaders.* import io.ktor.server.routing.* @@ -29,7 +28,7 @@ fun Application.module() { val widgetService = WidgetService() - install(Routing) { + routing { index() widget(widgetService) } @@ -37,5 +36,5 @@ fun Application.module() { } fun main(args: Array) { - embeddedServer(Netty, commandLineEnvironment(args)).start(wait = true) + EngineMain.main(args) } \ No newline at end of file diff --git a/src/main/kotlin/web/IndexResource.kt b/src/main/kotlin/web/IndexResource.kt index 6d4217f..31191ba 100644 --- a/src/main/kotlin/web/IndexResource.kt +++ b/src/main/kotlin/web/IndexResource.kt @@ -1,7 +1,6 @@ package web import io.ktor.http.* -import io.ktor.server.application.* import io.ktor.server.response.* import io.ktor.server.routing.* diff --git a/src/main/kotlin/web/WidgetResource.kt b/src/main/kotlin/web/WidgetResource.kt index 1c99a9f..bd7e258 100644 --- a/src/main/kotlin/web/WidgetResource.kt +++ b/src/main/kotlin/web/WidgetResource.kt @@ -1,7 +1,6 @@ package web import io.ktor.http.* -import io.ktor.server.application.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* diff --git a/src/test/kotlin/common/ServerTest.kt b/src/test/kotlin/common/ServerTest.kt index 200ec55..cbad7b9 100644 --- a/src/test/kotlin/common/ServerTest.kt +++ b/src/test/kotlin/common/ServerTest.kt @@ -36,7 +36,7 @@ open class ServerTest { private var serverStarted = false - private lateinit var server: ApplicationEngine + private lateinit var server: EmbeddedServer @BeforeAll @JvmStatic