Skip to content

Commit

Permalink
Bump Ktor to 3.0.0 and Kotlin to 2.0.20 (#197)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Stexxe authored Oct 10, 2024
1 parent 1ac6457 commit f8f6e53
Show file tree
Hide file tree
Showing 67 changed files with 230 additions and 554 deletions.
9 changes: 6 additions & 3 deletions chat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
classpath "org.jetbrains.kotlin:kotlin-serialization:2.0.20"
}
}

apply plugin: 'kotlin-multiplatform'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'

kotlin {
targets {
Expand All @@ -28,14 +30,14 @@ kotlin {

sourceSets.each {
it.dependencies {
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:2.3.12"))
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:3.0.0"))
}
}

sourceSets {
backendMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20"
implementation "io.ktor:ktor-server-netty"
implementation "io.ktor:ktor-server-websockets"
implementation "io.ktor:ktor-server-call-logging"
Expand Down Expand Up @@ -70,6 +72,7 @@ repositories {

tasks.named("backendProcessResources").configure {
dependsOn("frontendBrowserProductionWebpack")
dependsOn("frontendBrowserDistribution")
}

tasks.register("run", JavaExec) {
Expand Down
17 changes: 7 additions & 10 deletions chat/src/backendMain/kotlin/ChatApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.http.content.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.calllogging.CallLogging
import io.ktor.server.plugins.defaultheaders.*
import io.ktor.server.routing.*
import io.ktor.server.sessions.*
import io.ktor.server.websocket.*
import io.ktor.util.*
import io.ktor.websocket.*
import kotlinx.coroutines.channels.*
import java.time.*
import kotlinx.serialization.Serializable
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes

/**
* An entry point of the application.
Expand Down Expand Up @@ -61,7 +63,7 @@ class ChatApplication {
// This installs the WebSockets plugin to be able to establish a bidirectional configuration
// between the server and the client
install(WebSockets) {
pingPeriod = Duration.ofMinutes(1)
pingPeriod = 1.minutes
}
// This enables the use of sessions to keep information between requests/refreshes of the browser.
install(Sessions) {
Expand Down Expand Up @@ -121,19 +123,14 @@ class ChatApplication {
}

// This defines a block of static resources for the '/' path (since no path is specified and we start at '/')
static {
// This marks index.html from the 'web' folder in resources as the default file to serve.
defaultResource("index.html", "web")
// This serves files from the 'web' folder in the application resources.
resources("web")
}

staticResources("", "web")
}
}

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

/**
Expand Down
8 changes: 7 additions & 1 deletion chat/src/backendTest/kotlin/ChatApplicationTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.ktor.samples.chat.backend

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

Expand Down Expand Up @@ -57,6 +60,9 @@ class ChatApplicationTest {
fun testDualConversation() {
// Creates the [TestApplicationEngine] with the [Application::main] module. Check the previous test for more details.
testApplication {
environment {
config = ApplicationConfig(null)
}
// Sets to hold the messages from each children.
// Since this is multithreaded and socket-related.
// The order might change in each run, so we use a Set instead of a List to check that the messages
Expand Down
1 change: 1 addition & 0 deletions chat/src/frontendMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fun main() {
})
}

@OptIn(DelicateCoroutinesApi::class)
suspend fun initConnection(wsClient: WsClient) {
try {
wsClient.connect()
Expand Down
2 changes: 1 addition & 1 deletion client-mpp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
classpath("com.android.tools.build:gradle:7.0.4")
}
}
Expand Down
2 changes: 1 addition & 1 deletion client-mpp/shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kotlin {

sourceSets.each {
it.dependencies {
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:2.3.12"))
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:3.0.0"))
}
}

Expand Down
6 changes: 3 additions & 3 deletions client-multipart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
classpath "io.ktor.plugin:plugin:2.3.12"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
classpath "io.ktor.plugin:plugin:3.0.0"
}
}

Expand All @@ -27,7 +27,7 @@ repositories {
}

dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20'
implementation "io.ktor:ktor-server-html-builder"
implementation 'ch.qos.logback:logback-classic:1.4.6'
implementation 'io.ktor:ktor-server-netty-jvm'
Expand Down
6 changes: 3 additions & 3 deletions client-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
classpath "io.ktor.plugin:plugin:2.3.12"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
classpath "io.ktor.plugin:plugin:3.0.0"
}
}

Expand All @@ -27,7 +27,7 @@ repositories {
}

dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20'
implementation "io.ktor:ktor-server-html-builder"
implementation 'ch.qos.logback:logback-classic:1.4.6'
implementation 'io.ktor:ktor-server-netty-jvm'
Expand Down
8 changes: 4 additions & 4 deletions di-kodein/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ val kotlin_version: String by project
val logback_version: String by project

plugins {
kotlin("jvm") version "1.9.21"
id("io.ktor.plugin") version "2.3.12"
kotlin("plugin.serialization") version "1.9.21"
kotlin("jvm") version "2.0.20"
id("io.ktor.plugin") version "3.0.0"
kotlin("plugin.serialization") version "2.0.20"
}

application {
Expand All @@ -23,6 +23,6 @@ dependencies {
implementation("io.ktor:ktor-server-html-builder")
implementation("org.kodein.di:kodein-di-jvm:7.17.0")
implementation("ch.qos.logback:logback-classic:$logback_version")
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("io.ktor:ktor-server-test-host-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
4 changes: 2 additions & 2 deletions di-kodein/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kotlin_version=1.9.21
logback_version=1.2.11
kotlin_version=2.0.20
logback_version=1.3.14
kotlin.code.style=official
6 changes: 3 additions & 3 deletions filelisting/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ val kotlin_version: String by project
val logback_version: String by project

plugins {
kotlin("jvm") version "1.9.21"
id("io.ktor.plugin") version "2.3.12"
kotlin("jvm") version "2.0.20"
id("io.ktor.plugin") version "3.0.0"
}

application {
Expand All @@ -20,7 +20,7 @@ dependencies {
implementation("io.ktor:ktor-server-default-headers")
implementation("io.ktor:ktor-server-html-builder")
implementation("io.ktor:ktor-server-call-logging")
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("io.ktor:ktor-server-test-host-jvm")
implementation("ch.qos.logback:logback-classic:$logback_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
4 changes: 2 additions & 2 deletions filelisting/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kotlin_version=1.9.21
logback_version=1.2.11
kotlin_version=2.0.20
logback_version=1.3.14
kotlin.code.style=official
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.ktor.server.html.*
import io.ktor.server.http.content.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.calllogging.CallLogging
import io.ktor.server.plugins.defaultheaders.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down Expand Up @@ -35,7 +35,7 @@ fun main() {
call.respondInfo()
}
route("/myfiles") {
files(root)
staticFiles("", root)
listing(root)
}
}
Expand All @@ -53,7 +53,8 @@ suspend fun ApplicationCall.respondInfo() {
respondHtml {
body {
style {
+"""
unsafe {
"""
table {
font: 1em Arial;
border: 1px solid black;
Expand All @@ -71,6 +72,7 @@ suspend fun ApplicationCall.respondInfo() {
padding: 0.5em 1em;
}
""".trimIndent()
}
}
h1 {
+"Ktor info"
Expand Down Expand Up @@ -109,32 +111,28 @@ suspend fun ApplicationCall.respondInfo() {
row("request.ranges()", request.ranges())
}

for (
(name, value) in listOf(
"request.local" to request.local,
"request.origin" to request.origin
)
) {
for ((name, value) in listOf(
"request.local" to request.local,
"request.origin" to request.origin
)) {
h2 {
+name
}
table {
row("$name.version", value.version)
row("$name.method", value.method)
row("$name.scheme", value.scheme)
row("$name.host", value.host)
row("$name.port", value.port)
row("$name.host", value.localHost)
row("$name.port", value.localPort)
row("$name.remoteHost", value.remoteHost)
row("$name.uri", value.uri)
}
}

for (
(name, parameters) in listOf(
"Query parameters" to request.queryParameters,
"Headers" to request.headers
)
) {
for ((name, parameters) in listOf(
"Query parameters" to request.queryParameters,
"Headers" to request.headers
)) {
h2 {
+name
}
Expand Down
4 changes: 2 additions & 2 deletions fullstack-mpp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
}
}

Expand All @@ -29,7 +29,7 @@ kotlin {

sourceSets.each {
it.dependencies {
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:2.3.12"))
implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:3.0.0"))
}
}

Expand Down
4 changes: 2 additions & 2 deletions graalvm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
application
kotlin("jvm") version "1.9.21"
id("io.ktor.plugin") version "2.3.12"
kotlin("jvm") version "2.0.20"
id("io.ktor.plugin") version "3.0.0"
id("org.graalvm.buildtools.native") version "0.9.19"
}

Expand Down
6 changes: 3 additions & 3 deletions h2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ val logback_version: String by project

plugins {
application
kotlin("jvm") version "1.9.21"
id("io.ktor.plugin") version "2.3.12"
kotlin("jvm") version "2.0.20"
id("io.ktor.plugin") version "3.0.0"
}

group = "io.ktor.samples"
Expand All @@ -29,6 +29,6 @@ dependencies {
implementation("io.ktor:ktor-server-netty-jvm")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-server-html-builder")
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("io.ktor:ktor-server-test-host-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
4 changes: 2 additions & 2 deletions h2/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kotlin_version=1.9.21
logback_version=1.2.11
kotlin_version=2.0.20
logback_version=1.3.14
kotlin.code.style=official
6 changes: 3 additions & 3 deletions httpbin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ val kotlin_version: String by project
val logback_version: String by project

plugins {
kotlin("jvm") version "1.9.21"
id("io.ktor.plugin") version "2.3.12"
kotlin("jvm") version "2.0.20"
id("io.ktor.plugin") version "3.0.0"
}

application {
Expand Down Expand Up @@ -31,7 +31,7 @@ dependencies {
implementation("io.ktor:ktor-server-html-builder")
implementation("io.ktor:ktor-server-partial-content")
implementation("ch.qos.logback:logback-classic:$logback_version")
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("io.ktor:ktor-server-test-host-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}

Expand Down
Loading

0 comments on commit f8f6e53

Please sign in to comment.