From 18aa2a64acd81d4833888a41a346030344ce34fd Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Mon, 17 Feb 2025 17:36:14 -0500 Subject: [PATCH] modernize gradle build --- build.gradle.kts | 55 +++--- buildSrc/.gitignore | 3 - buildSrc/build.gradle.kts | 22 --- buildSrc/settings.gradle.kts | 26 --- buildSrc/src/main/kotlin/Libs.kt | 55 ------ gradle/libs.versions.toml | 165 ++++++++++++++++++ settings.gradle.kts | 23 +-- .../slackbot/osrs/ItemMapper.kt | 11 +- versions.properties | 154 ---------------- 9 files changed, 198 insertions(+), 316 deletions(-) delete mode 100644 buildSrc/.gitignore delete mode 100644 buildSrc/build.gradle.kts delete mode 100644 buildSrc/settings.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/Libs.kt create mode 100644 gradle/libs.versions.toml delete mode 100644 versions.properties diff --git a/build.gradle.kts b/build.gradle.kts index 2835257..7e2a4f6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,21 +1,9 @@ -buildscript { - dependencies { - constraints { - classpath("org.apache.logging.log4j:log4j-core") { - version { - strictly("[2.17, 3[") - prefer("2.17.0") - } - because("CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities") - } - } - } -} - plugins { - id("com.github.johnrengelman.shadow") version Libs.com_github_johnrengelman_shadow_gradle_plugin - kotlin("jvm") version "2.1.10" + alias(libs.plugins.com.gradleup.shadow) + alias(libs.plugins.org.jetbrains.kotlin.jvm) + alias(libs.plugins.org.jetbrains.kotlin.plugin.serialization) application + `jvm-test-suite` } group = "com.anthonycicchetti" @@ -27,7 +15,7 @@ repositories { dependencies { constraints { - implementation("org.apache.logging.log4j:log4j-core") { + implementation("org.apache.logging.log4j:log4j-core:_") { version { strictly("[2.17, 3[") prefer("2.17.0") @@ -35,19 +23,17 @@ dependencies { because("CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities") } } - implementation(Kotlin.stdlib.jdk8) - implementation(Libs.javalin) - implementation(Libs.javalin_openapi) - implementation(Libs.slf4j_simple) - implementation(Libs.jackson_databind) - implementation(Libs.jackson_module_kotlin) - implementation(Libs.swagger_core) - implementation(Libs.swagger_ui) - implementation(Libs.slack_api_model_kotlin_extension) - implementation(Libs.ktor_client_cio) - implementation(Libs.ktor_client_core) + implementation(libs.javalin) + implementation(libs.javalin.openapi) + implementation(libs.slf4j.simple) + implementation(libs.swagger.core) + implementation(libs.swagger.ui) + implementation(libs.slack.api.model.kotlin.extension) + implementation(libs.ktor.client.core) + implementation(libs.ktor.client.cio) + implementation(KotlinX.serialization.json) - testImplementation(Libs.junit_jupiter) + testImplementation(libs.junit.jupiter) } application { @@ -60,9 +46,10 @@ java { } } -tasks.withType { - useJUnitPlatform() - testLogging { - events("passed", "skipped", "failed") +testing { + suites { + val test by getting(JvmTestSuite::class) { + useJUnitJupiter() + } } -} +} \ No newline at end of file diff --git a/buildSrc/.gitignore b/buildSrc/.gitignore deleted file mode 100644 index ea958e5..0000000 --- a/buildSrc/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ - -.gradle/ -build/ diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index 741bd01..0000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,22 +0,0 @@ -buildscript { - dependencies { - constraints { - classpath("org.apache.logging.log4j:log4j-core") { - version { - strictly("[2.17, 3[") - prefer("2.17.0") - } - because("CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities") - } - } - } -} - - -repositories { - mavenCentral() -} - -plugins { - `kotlin-dsl` -} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts deleted file mode 100644 index 909fd09..0000000 --- a/buildSrc/settings.gradle.kts +++ /dev/null @@ -1,26 +0,0 @@ -pluginManagement { - repositories { - gradlePluginPortal() - } - plugins { - id("de.fayard.refreshVersions") version "0.40.2" - } -} - -buildscript { - dependencies { - constraints { - classpath("org.apache.logging.log4j:log4j-core") { - version { - strictly("[2.17, 3[") - prefer("2.17.0") - } - because("CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities") - } - } - } -} - -plugins { - id("de.fayard.refreshVersions") -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt deleted file mode 100644 index f698581..0000000 --- a/buildSrc/src/main/kotlin/Libs.kt +++ /dev/null @@ -1,55 +0,0 @@ -import kotlin.String - -/** - * Generated by - * $ ./gradlew buildSrcLibs - * Re-run when you add a new dependency to the build - * - * Find which updates are available by running - * $ ./gradlew refreshVersions - * And edit the file `versions.properties` - * - * See https://github.com/Splitties/refreshVersions - */ -public object Libs { - public const val jackson_databind: String = "com.fasterxml.jackson.core:jackson-databind:_" - - public const val jackson_module_kotlin: String = - "com.fasterxml.jackson.module:jackson-module-kotlin:_" - - public const val com_github_johnrengelman_shadow_gradle_plugin: String = - "com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:_" - - public const val slack_api_model_kotlin_extension: String = - "com.slack.api:slack-api-model-kotlin-extension:_" - - public const val de_fayard_buildsrclibs_gradle_plugin: String = - "de.fayard.buildSrcLibs:de.fayard.buildSrcLibs.gradle.plugin:_" - - public const val javalin: String = "io.javalin:javalin:_" - - public const val javalin_openapi: String = "io.javalin:javalin-openapi:_" - - public const val ktor_client_cio: String = "io.ktor:ktor-client-cio:_" - - public const val ktor_client_core: String = "io.ktor:ktor-client-core:_" - - public const val swagger_core: String = "io.swagger.core.v3:swagger-core:_" - - public const val org_jetbrains_kotlin_jvm_gradle_plugin: String = - "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:_" - - public const val kotlin_build_tools_impl: String = - "org.jetbrains.kotlin:kotlin-build-tools-impl" - - public const val kotlin_scripting_compiler_embeddable: String = - "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:_" - - public const val kotlin_stdlib_jdk8: String = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:_" - - public const val junit_jupiter: String = "org.junit.jupiter:junit-jupiter:_" - - public const val slf4j_simple: String = "org.slf4j:slf4j-simple:_" - - public const val swagger_ui: String = "org.webjars:swagger-ui:_" -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..c0a98cf --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,165 @@ +## Generated by $ ./gradlew refreshVersionsCatalog + +[plugins] + +org-jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } + +org-jetbrains-kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } + +org-gradle-kotlin-kotlin-dsl = { id = "org.gradle.kotlin.kotlin-dsl", version = "5.1.2" } + +com-gradleup-shadow = { id = "com.gradleup.shadow", version = "9.0.0-beta8" } + +[versions] + +kotlin = "2.1.10" +## ⬆ = "2.1.20-Beta1" +## ⬆ = "2.1.20-Beta2" + +ktor = "3.1.0" + +kotlinx-serialization = "1.8.0" + +junit-jupiter = "5.11.4" +## ⬆ = "5.12.0-M1" +## ⬆ = "5.12.0-RC1" +## ⬆ = "5.12.0-RC2" + +[libraries] + +javalin = "io.javalin:javalin:4.6.8" +## ⬆ :5.0.0.RC0" +## ⬆ :5.0.0.RC1" +## ⬆ :5.0.0.RC2" +## ⬆ :5.0.0" +## ⬆ :5.0.1" +## ⬆ :5.1.0" +## ⬆ :5.1.1" +## ⬆ :5.1.2" +## ⬆ :5.1.3" +## ⬆ :5.1.4" +## ⬆ :5.2.0" +## ⬆ :5.3.0" +## ⬆ :5.3.1" +## ⬆ :5.3.2" +## ⬆ :5.4.0" +## ⬆ :5.4.1" +## ⬆ :5.4.2" +## ⬆ :5.5.0" +## ⬆ :5.6.0" +## ⬆ :5.6.1" +## ⬆ :5.6.2" +## ⬆ :5.6.3" +## ⬆ :5.6.4" +## ⬆ :5.6.5" +## ⬆ :6.0.0-beta.1" +## ⬆ :6.0.0-beta.2" +## ⬆ :6.0.0-beta.3" +## ⬆ :6.0.0-beta.4" +## ⬆ :6.0.0" +## ⬆ :6.0.1" +## ⬆ :6.1.0" +## ⬆ :6.1.1" +## ⬆ :6.1.2" +## ⬆ :6.1.3" +## ⬆ :6.1.4" +## ⬆ :6.1.6" +## ⬆ :6.2.0" +## ⬆ :6.3.0" +## ⬆ :6.4.0" + +javalin-openapi = "io.javalin:javalin-openapi:4.6.8" + +slf4j-simple = "org.slf4j:slf4j-simple:1.7.36" +## ⬆ :1.8.0-alpha0" +## ⬆ :1.8.0-alpha1" +## ⬆ :1.8.0-alpha2" +## ⬆ :1.8.0-beta0" +## ⬆ :1.8.0-beta1" +## ⬆ :1.8.0-beta2" +## ⬆ :1.8.0-beta4" +## ⬆ :2.0.0-alpha0" +## ⬆ :2.0.0-alpha1" +## ⬆ :2.0.0-alpha2" +## ⬆ :2.0.0-alpha3" +## ⬆ :2.0.0-alpha4" +## ⬆ :2.0.0-alpha5" +## ⬆ :2.0.0-alpha6" +## ⬆ :2.0.0-alpha7" +## ⬆ :2.0.0-beta0" +## ⬆ :2.0.0-beta1" +## ⬆ :2.0.0" +## ⬆ :2.0.1" +## ⬆ :2.0.2" +## ⬆ :2.0.3" +## ⬆ :2.0.4" +## ⬆ :2.0.5" +## ⬆ :2.0.6" +## ⬆ :2.0.7" +## ⬆ :2.0.8" +## ⬆ :2.0.9" +## ⬆ :2.0.10" +## ⬆ :2.0.11" +## ⬆ :2.0.12" +## ⬆ :2.0.13" +## ⬆ :2.0.14" +## ⬆ :2.0.15" +## ⬆ :2.0.16" +## ⬆ :2.1.0-alpha0" +## ⬆ :2.1.0-alpha1" + +swagger-core = "io.swagger.core.v3:swagger-core:2.2.28" + +swagger-ui = "org.webjars:swagger-ui:4.19.1" +## ⬆ :5.0.0" +## ⬆ :5.1.0" +## ⬆ :5.1.2" +## ⬆ :5.1.3" +## ⬆ :5.2.0" +## ⬆ :5.3.1" +## ⬆ :5.4.2" +## ⬆ :5.5.0" +## ⬆ :5.6.1" +## ⬆ :5.7.2" +## ⬆ :5.9.0" +## ⬆ :5.10.3" +## ⬆ :5.11.8" +## ⬆ :5.11.9" +## ⬆ :5.11.10" +## ⬆ :5.12.0" +## ⬆ :5.12.2" +## ⬆ :5.13.0" +## ⬆ :5.14.0" +## ⬆ :5.15.0" +## ⬆ :5.15.1" +## ⬆ :5.15.2" +## ⬆ :5.15.2-1" +## ⬆ :5.17.0" +## ⬆ :5.17.1" +## ⬆ :5.17.2" +## ⬆ :5.17.6" +## ⬆ :5.17.7" +## ⬆ :5.17.11" +## ⬆ :5.17.14" +## ⬆ :5.18.0" +## ⬆ :5.18.1" +## ⬆ :5.18.2" +## ⬆ :5.18.3" + +slack-api-model-kotlin-extension = "com.slack.api:slack-api-model-kotlin-extension:1.45.2" + +kotlin-build-tools-impl = { module = "org.jetbrains.kotlin:kotlin-build-tools-impl" } + +kotlin-scripting-compiler-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-scripting-compiler-embeddable", version.ref = "kotlin" } + +kotlin-serialization-compiler-plugin-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-serialization-compiler-plugin-embeddable", version.ref = "kotlin" } + +kotlin-stdlib-jdk8 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" } + +ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktor" } + +ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" } + +kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" } + +junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 06786df..27d6fe8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,24 +9,11 @@ pluginManagement { } } -buildscript { - dependencies { - constraints { - classpath("org.apache.logging.log4j:log4j-core") { - version { - strictly("[2.17, 3[") - prefer("2.17.0") - } - because("CVE-2021-44228, CVE-2021-45046, CVE-2021-45105: Log4j vulnerable to remote code execution and other critical security vulnerabilities") - } - } - } -} - -refreshVersions { - enableBuildSrcLibs() -} - plugins { id("de.fayard.refreshVersions") } + +refreshVersions { + file("build/tmp/refreshVersions").mkdirs() + versionsPropertiesFile = file("build/tmp/refreshVersions/versions.properties") +} \ No newline at end of file diff --git a/src/main/kotlin/com/anthonycicchetti/slackbot/osrs/ItemMapper.kt b/src/main/kotlin/com/anthonycicchetti/slackbot/osrs/ItemMapper.kt index 842790d..22d17db 100644 --- a/src/main/kotlin/com/anthonycicchetti/slackbot/osrs/ItemMapper.kt +++ b/src/main/kotlin/com/anthonycicchetti/slackbot/osrs/ItemMapper.kt @@ -9,7 +9,8 @@ import io.ktor.client.statement.* import io.ktor.client.call.* import io.ktor.client.engine.cio.* import io.ktor.client.plugins.* -import kotlinx.coroutines.* +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -27,7 +28,7 @@ suspend fun getItemList(): List { return when (response.status.value) { in 200..299 -> { logger.info("Got item mappings") - mapper.readValue(response.bodyAsText()) + Json.decodeFromString(response.body()) } else -> { @@ -45,7 +46,7 @@ suspend fun getOsrsItemPrice(item: ApiItem): Item { .get("https://prices.runescape.wiki/api/v1/osrs/latest") return when (response.status.value) { in 200..299 -> { - val r: Resp = mapper.readValue(response.body()) + val r: Resp = Json.decodeFromString(response.body()) r.data.getOrDefault(item.id.toString(), Item()) } @@ -56,10 +57,12 @@ suspend fun getOsrsItemPrice(item: ApiItem): Item { } } +@Serializable private data class Resp( val data: Map = emptyMap(), ) +@Serializable data class Item( val low: Int = 0, val lowTime: Long = 0L, @@ -68,7 +71,7 @@ data class Item( ) -@JsonIgnoreProperties(ignoreUnknown = true) +@Serializable data class ApiItem( val examine: String = "Empty Examine Text", val id: Int = 0, diff --git a/versions.properties b/versions.properties deleted file mode 100644 index 1518a52..0000000 --- a/versions.properties +++ /dev/null @@ -1,154 +0,0 @@ -#### Dependencies and Plugin versions with their available updates. -#### Generated by `./gradlew refreshVersions` version 0.60.5 -#### -#### Don't manually edit or split the comments that start with four hashtags (####), -#### they will be overwritten by refreshVersions. -#### -#### suppress inspection "SpellCheckingInspection" for whole file -#### suppress inspection "UnusedProperty" for whole file - -plugin.com.github.johnrengelman.shadow=8.1.1 - -plugin.de.fayard.buildSrcLibs=0.60.5 - -plugin.org.gradle.kotlin.kotlin-dsl=5.1.2 -## # available=5.2.0 - -version.com.fasterxml.jackson.core..jackson-databind=2.18.2 - -version.com.fasterxml.jackson.module..jackson-module-kotlin=2.18.2 - -version.com.slack.api..slack-api-model-kotlin-extension=1.45.2 - -version.io.javalin..javalin=4.6.8 -## # available=5.0.0.RC0 -## # available=5.0.0.RC1 -## # available=5.0.0.RC2 -## # available=5.0.0 -## # available=5.0.1 -## # available=5.1.0 -## # available=5.1.1 -## # available=5.1.2 -## # available=5.1.3 -## # available=5.1.4 -## # available=5.2.0 -## # available=5.3.0 -## # available=5.3.1 -## # available=5.3.2 -## # available=5.4.0 -## # available=5.4.1 -## # available=5.4.2 -## # available=5.5.0 -## # available=5.6.0 -## # available=5.6.1 -## # available=5.6.2 -## # available=5.6.3 -## # available=5.6.4 -## # available=5.6.5 -## # available=6.0.0-beta.1 -## # available=6.0.0-beta.2 -## # available=6.0.0-beta.3 -## # available=6.0.0-beta.4 -## # available=6.0.0 -## # available=6.0.1 -## # available=6.1.0 -## # available=6.1.1 -## # available=6.1.2 -## # available=6.1.3 -## # available=6.1.4 -## # available=6.1.6 -## # available=6.2.0 -## # available=6.3.0 -## # available=6.4.0 - -version.io.javalin..javalin-openapi=4.6.8 - -version.io.swagger.core.v3..swagger-core=2.2.28 - -## unused -version.junit=5.8.2 - -version.junit.jupiter=5.11.4 -## # available=5.12.0-M1 -## # available=5.12.0-RC1 -## # available=5.12.0-RC2 - -version.kotlin=2.1.10 -## # available=2.1.20-Beta1 -## # available=2.1.20-Beta2 - -version.ktor=3.1.0 - -version.org.slf4j..slf4j-simple=1.7.36 -## # available=1.8.0-alpha0 -## # available=1.8.0-alpha1 -## # available=1.8.0-alpha2 -## # available=1.8.0-beta0 -## # available=1.8.0-beta1 -## # available=1.8.0-beta2 -## # available=1.8.0-beta4 -## # available=2.0.0-alpha0 -## # available=2.0.0-alpha1 -## # available=2.0.0-alpha2 -## # available=2.0.0-alpha3 -## # available=2.0.0-alpha4 -## # available=2.0.0-alpha5 -## # available=2.0.0-alpha6 -## # available=2.0.0-alpha7 -## # available=2.0.0-beta0 -## # available=2.0.0-beta1 -## # available=2.0.0 -## # available=2.0.1 -## # available=2.0.2 -## # available=2.0.3 -## # available=2.0.4 -## # available=2.0.5 -## # available=2.0.6 -## # available=2.0.7 -## # available=2.0.8 -## # available=2.0.9 -## # available=2.0.10 -## # available=2.0.11 -## # available=2.0.12 -## # available=2.0.13 -## # available=2.0.14 -## # available=2.0.15 -## # available=2.0.16 -## # available=2.1.0-alpha0 -## # available=2.1.0-alpha1 - -version.org.webjars..swagger-ui=4.19.1 -## # available=5.0.0 -## # available=5.1.0 -## # available=5.1.2 -## # available=5.1.3 -## # available=5.2.0 -## # available=5.3.1 -## # available=5.4.2 -## # available=5.5.0 -## # available=5.6.1 -## # available=5.7.2 -## # available=5.9.0 -## # available=5.10.3 -## # available=5.11.8 -## # available=5.11.9 -## # available=5.11.10 -## # available=5.12.0 -## # available=5.12.2 -## # available=5.13.0 -## # available=5.14.0 -## # available=5.15.0 -## # available=5.15.1 -## # available=5.15.2 -## # available=5.15.2-1 -## # available=5.17.0 -## # available=5.17.1 -## # available=5.17.2 -## # available=5.17.6 -## # available=5.17.7 -## # available=5.17.11 -## # available=5.17.14 -## # available=5.18.0 -## # available=5.18.1 -## # available=5.18.2 -## # available=5.18.3