Skip to content

Commit f8f6e53

Browse files
authored
Bump Ktor to 3.0.0 and Kotlin to 2.0.20 (#197)
* Bump Ktor to 3.0.0 and Kotlin to 2.0.20 * Migrate to Ktor 3.0.0 * Fix tests * Remove comment * Downgrade version of logback
1 parent 1ac6457 commit f8f6e53

File tree

67 files changed

+230
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+230
-554
lines changed

chat/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ buildscript {
33
mavenCentral()
44
}
55
dependencies {
6-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
6+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
7+
classpath "org.jetbrains.kotlin:kotlin-serialization:2.0.20"
78
}
89
}
910

1011
apply plugin: 'kotlin-multiplatform'
12+
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
1113

1214
kotlin {
1315
targets {
@@ -28,14 +30,14 @@ kotlin {
2830

2931
sourceSets.each {
3032
it.dependencies {
31-
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:2.3.12"))
33+
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:3.0.0"))
3234
}
3335
}
3436

3537
sourceSets {
3638
backendMain {
3739
dependencies {
38-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21"
40+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20"
3941
implementation "io.ktor:ktor-server-netty"
4042
implementation "io.ktor:ktor-server-websockets"
4143
implementation "io.ktor:ktor-server-call-logging"
@@ -70,6 +72,7 @@ repositories {
7072

7173
tasks.named("backendProcessResources").configure {
7274
dependsOn("frontendBrowserProductionWebpack")
75+
dependsOn("frontendBrowserDistribution")
7376
}
7477

7578
tasks.register("run", JavaExec) {

chat/src/backendMain/kotlin/ChatApplication.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import io.ktor.server.application.*
44
import io.ktor.server.engine.*
55
import io.ktor.server.http.content.*
66
import io.ktor.server.netty.*
7-
import io.ktor.server.plugins.callloging.*
7+
import io.ktor.server.plugins.calllogging.CallLogging
88
import io.ktor.server.plugins.defaultheaders.*
99
import io.ktor.server.routing.*
1010
import io.ktor.server.sessions.*
1111
import io.ktor.server.websocket.*
1212
import io.ktor.util.*
1313
import io.ktor.websocket.*
1414
import kotlinx.coroutines.channels.*
15-
import java.time.*
15+
import kotlinx.serialization.Serializable
16+
import kotlin.time.Duration
17+
import kotlin.time.Duration.Companion.minutes
1618

1719
/**
1820
* An entry point of the application.
@@ -61,7 +63,7 @@ class ChatApplication {
6163
// This installs the WebSockets plugin to be able to establish a bidirectional configuration
6264
// between the server and the client
6365
install(WebSockets) {
64-
pingPeriod = Duration.ofMinutes(1)
66+
pingPeriod = 1.minutes
6567
}
6668
// This enables the use of sessions to keep information between requests/refreshes of the browser.
6769
install(Sessions) {
@@ -121,19 +123,14 @@ class ChatApplication {
121123
}
122124

123125
// This defines a block of static resources for the '/' path (since no path is specified and we start at '/')
124-
static {
125-
// This marks index.html from the 'web' folder in resources as the default file to serve.
126-
defaultResource("index.html", "web")
127-
// This serves files from the 'web' folder in the application resources.
128-
resources("web")
129-
}
130-
126+
staticResources("", "web")
131127
}
132128
}
133129

134130
/**
135131
* A chat session is identified by a unique nonce ID. This nonce comes from a secure random source.
136132
*/
133+
@Serializable
137134
data class ChatSession(val id: String)
138135

139136
/**

chat/src/backendTest/kotlin/ChatApplicationTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.ktor.samples.chat.backend
22

33
import io.ktor.client.plugins.websocket.*
4-
import io.ktor.server.application.*
4+
import io.ktor.server.config.ApplicationConfig
55
import io.ktor.server.testing.*
66
import io.ktor.websocket.*
77
import kotlin.test.*
@@ -18,6 +18,9 @@ class ChatApplicationTest {
1818
// First, we create a [TestApplicationEngine] that includes the module [Application.main],
1919
// this executes that function and thus installs all the plugins and routes to this test application.
2020
testApplication {
21+
environment {
22+
config = ApplicationConfig(null)
23+
}
2124
// Keeps a log array that will hold all the events we want to check later at once.
2225
val log = arrayListOf<String>()
2326

@@ -57,6 +60,9 @@ class ChatApplicationTest {
5760
fun testDualConversation() {
5861
// Creates the [TestApplicationEngine] with the [Application::main] module. Check the previous test for more details.
5962
testApplication {
63+
environment {
64+
config = ApplicationConfig(null)
65+
}
6066
// Sets to hold the messages from each children.
6167
// Since this is multithreaded and socket-related.
6268
// The order might change in each run, so we use a Set instead of a List to check that the messages

chat/src/frontendMain/kotlin/main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fun main() {
3030
})
3131
}
3232

33+
@OptIn(DelicateCoroutinesApi::class)
3334
suspend fun initConnection(wsClient: WsClient) {
3435
try {
3536
wsClient.connect()

client-mpp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
gradlePluginPortal()
66
}
77
dependencies {
8-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21")
8+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
99
classpath("com.android.tools.build:gradle:7.0.4")
1010
}
1111
}

client-mpp/shared/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kotlin {
1919

2020
sourceSets.each {
2121
it.dependencies {
22-
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:2.3.12"))
22+
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:3.0.0"))
2323
}
2424
}
2525

client-multipart/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ buildscript {
44
gradlePluginPortal()
55
}
66
dependencies {
7-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
8-
classpath "io.ktor.plugin:plugin:2.3.12"
7+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
8+
classpath "io.ktor.plugin:plugin:3.0.0"
99
}
1010
}
1111

@@ -27,7 +27,7 @@ repositories {
2727
}
2828

2929
dependencies {
30-
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21'
30+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20'
3131
implementation "io.ktor:ktor-server-html-builder"
3232
implementation 'ch.qos.logback:logback-classic:1.4.6'
3333
implementation 'io.ktor:ktor-server-netty-jvm'

client-tools/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ buildscript {
44
gradlePluginPortal()
55
}
66
dependencies {
7-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
8-
classpath "io.ktor.plugin:plugin:2.3.12"
7+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
8+
classpath "io.ktor.plugin:plugin:3.0.0"
99
}
1010
}
1111

@@ -27,7 +27,7 @@ repositories {
2727
}
2828

2929
dependencies {
30-
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21'
30+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20'
3131
implementation "io.ktor:ktor-server-html-builder"
3232
implementation 'ch.qos.logback:logback-classic:1.4.6'
3333
implementation 'io.ktor:ktor-server-netty-jvm'

di-kodein/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ val kotlin_version: String by project
22
val logback_version: String by project
33

44
plugins {
5-
kotlin("jvm") version "1.9.21"
6-
id("io.ktor.plugin") version "2.3.12"
7-
kotlin("plugin.serialization") version "1.9.21"
5+
kotlin("jvm") version "2.0.20"
6+
id("io.ktor.plugin") version "3.0.0"
7+
kotlin("plugin.serialization") version "2.0.20"
88
}
99

1010
application {
@@ -23,6 +23,6 @@ dependencies {
2323
implementation("io.ktor:ktor-server-html-builder")
2424
implementation("org.kodein.di:kodein-di-jvm:7.17.0")
2525
implementation("ch.qos.logback:logback-classic:$logback_version")
26-
testImplementation("io.ktor:ktor-server-tests-jvm")
26+
testImplementation("io.ktor:ktor-server-test-host-jvm")
2727
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
2828
}

di-kodein/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
kotlin_version=1.9.21
2-
logback_version=1.2.11
1+
kotlin_version=2.0.20
2+
logback_version=1.3.14
33
kotlin.code.style=official

0 commit comments

Comments
 (0)