From 144649a4570cffdc6426e20073002dae9b9fd5e5 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Wed, 17 Nov 2021 16:45:43 +0100 Subject: Upgrade to Kotlin 1.6.0 and JDK 17 --- build.gradle.kts | 13 +++---------- gradle/libs.versions.toml | 9 +++++---- .../org/luxons/sevenwonders/model/api/actions/Actions.kt | 4 ++-- sw-server/Dockerfile | 2 +- .../sevenwonders/server/controllers/AutoGameController.kt | 5 ++--- .../sevenwonders/server/controllers/LobbyController.kt | 4 ++-- .../luxons/sevenwonders/server/test/ClientEventsAsserts.kt | 10 +++++----- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ac27625f..42ba7593 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,12 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { - val kotlinVersion = "1.5.31" + val kotlinVersion = "1.6.0" kotlin("js") version kotlinVersion apply false kotlin("jvm") version kotlinVersion apply false kotlin("multiplatform") version kotlinVersion apply false kotlin("plugin.spring") version kotlinVersion apply false kotlin("plugin.serialization") version kotlinVersion apply false - id("org.jlleitschuh.gradle.ktlint") version "10.1.0" } allprojects { @@ -17,20 +16,14 @@ allprojects { } subprojects { - apply(plugin = "org.jlleitschuh.gradle.ktlint") - - ktlint { - disabledRules.set(setOf("no-wildcard-imports")) - } - tasks.withType { // JVM only - kotlinOptions.jvmTarget = "15" + kotlinOptions.jvmTarget = "17" } tasks.withType> { kotlinOptions.freeCompilerArgs += listOf( "-Xopt-in=kotlin.RequiresOptIn", - "-Xopt-in=kotlin.time.ExperimentalTime", + "-Xopt-in=kotlin.time.ExperimentalTime", // for measureTimedValue and withTimeout(Duration) "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi" ) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5c9afcbe..aeefd17c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,10 +7,11 @@ loki-logback-appender = "1.0.0" micrometer-registry-prometheus = "1.6.1" slf4j = "1.7.30" -kotlin-react = "17.0.2-pre.265-kotlin-1.5.31" -kotlin-reactRedux = "7.2.4-pre.265-kotlin-1.5.31" -kotlin-reactRouterDom = "5.3.0-pre.265-kotlin-1.5.31" -kotlin-styled = "5.3.3-pre.265-kotlin-1.5.31" +# See https://github.com/JetBrains/kotlin-wrappers +kotlin-react = "17.0.2-pre.266-kotlin-1.6.0" +kotlin-reactRedux = "7.2.6-pre.266-kotlin-1.6.0" +kotlin-reactRouterDom = "5.3.0-pre.266-kotlin-1.6.0" +kotlin-styled = "5.3.3-pre.266-kotlin-1.6.0" kotlin-blueprintjs-core = "3.49.1-4" kotlin-blueprintjs-icons = "3.29.0-4" diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt index 4e877737..a41db7c1 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.Settings import org.luxons.sevenwonders.model.wonders.AssignedWonder -import kotlin.time.Duration +import kotlin.time.Duration.Companion.hours /** * The action to choose the player's name. This is the first action that should be called. @@ -110,7 +110,7 @@ class AddBotAction( /** * The global timeout for the bot, after which it disconnects (whether the game is over or not). */ - val globalBotTimeoutMillis: Long = Duration.hours(6).inWholeMilliseconds, + val globalBotTimeoutMillis: Long = 6.hours.inWholeMilliseconds, /** * The configuration of the bot to add. */ diff --git a/sw-server/Dockerfile b/sw-server/Dockerfile index 6d93473e..84a062a5 100644 --- a/sw-server/Dockerfile +++ b/sw-server/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:15 +FROM openjdk:17 EXPOSE 80 diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/AutoGameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/AutoGameController.kt index c94d49da..bfdef6e9 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/AutoGameController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/AutoGameController.kt @@ -14,9 +14,8 @@ import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController import java.security.Principal -import kotlin.time.Duration +import kotlin.time.Duration.Companion.minutes import kotlin.time.measureTimedValue -import kotlin.time.minutes import kotlin.time.toJavaDuration /** @@ -33,7 +32,7 @@ class AutoGameController( val client = SevenWondersClient() val serverUrl = "ws://localhost:$serverPort" - val lastTurn = withTimeout(Duration.minutes(5)) { + val lastTurn = withTimeout(5.minutes) { val (lastTurn, duration) = measureTimedValue { val otherBotNames = List(action.nbPlayers - 1) { "JoinerBot${it + 1}" } val owner = client.connectBot(serverUrl, "OwnerBot", action.config) diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt index 788430c8..41b38d72 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt @@ -27,7 +27,7 @@ import org.springframework.messaging.simp.SimpMessageSendingOperations import org.springframework.stereotype.Controller import org.springframework.validation.annotation.Validated import java.security.Principal -import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds /** * Handles actions in the game's lobby. The lobby is the place where players gather before a game. @@ -165,7 +165,7 @@ class LobbyController( } if (result == null) { meterRegistry.counter("bot.timeout", lobby.playerCountsTags()).increment() - val timeoutDuration = Duration.milliseconds(action.globalBotTimeoutMillis) + val timeoutDuration = action.globalBotTimeoutMillis.milliseconds logger.error("Bot {} timed out after {}", action.botDisplayName, timeoutDuration) bot.disconnect() } diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt index 65711d6d..62245764 100644 --- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt +++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt @@ -12,8 +12,8 @@ import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue import kotlin.time.Duration -import kotlin.time.milliseconds -import kotlin.time.seconds +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds class EventAsserter( val gameListEvents: ReceiveChannel, @@ -27,20 +27,20 @@ suspend fun SevenWondersSession.eventAsserter(scope: CoroutineScope): EventAsser return EventAsserter(gameListEvents, gameEvents) } -suspend inline fun EventAsserter.expectNoGameEvent(message: String? = null, timeout: Duration = Duration.milliseconds(50)) { +suspend inline fun EventAsserter.expectNoGameEvent(message: String? = null, timeout: Duration = 50.milliseconds) { val event = withTimeoutOrNull(timeout) { gameEvents.receive() } val extraMessage = message?.let { " ($it)" } ?: "" assertNull(event, "Expected no game event$extraMessage, but received $event") } -suspend inline fun EventAsserter.expectGameEvent(timeout: Duration = Duration.seconds(1)): T { +suspend inline fun EventAsserter.expectGameEvent(timeout: Duration = 1.seconds): T { val event = withTimeoutOrNull(timeout) { gameEvents.receive() } assertNotNull(event, "Expected event of type ${T::class.simpleName}, received nothing in $timeout") assertTrue(event is T, "Expected event of type ${T::class.simpleName}, received $event") return event } -suspend inline fun EventAsserter.expectGameListEvent(timeout: Duration = Duration.seconds(1)): T { +suspend inline fun EventAsserter.expectGameListEvent(timeout: Duration = 1.seconds): T { val event = withTimeoutOrNull(timeout) { gameListEvents.receive() } assertNotNull(event, "Expected event of type ${T::class.simpleName}, received nothing in $timeout") assertTrue(event is T, "Expected event of type ${T::class.simpleName}, received $event") -- cgit