From 49ed52165af50855487c4f5393a85944349eb1c8 Mon Sep 17 00:00:00 2001 From: Pierre-Marie Padiou Date: Wed, 27 Nov 2024 11:15:22 +0100 Subject: [PATCH] Manage dependencies with a version catalog (#727) [Version catalog](https://docs.gradle.org/current/userguide/version_catalogs.html) is the best practice for managing dependencies. It makes it easier to track and update versions, and allows to centralize dependencies in a multi-module context. It is an alternative to the `buildSrc` workaround used in some of our projects. This PR does not update libraries versions. We only manage versions (not full dependencies) in the version catalog. This gives all the benefit of centralizing versions, and we don't really need to define all dependencies in the version catalog if they are not used by several modules. --- gradle/libs.versions.toml | 21 +++++++++++ modules/core/build.gradle.kts | 65 +++++++++++++++-------------------- 2 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..c1d7d3642 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,21 @@ +[versions] +kotlin = "1.9.23" +kotlinx-coroutines = "1.7.3" +kotlinx-datetime = "0.6.0" +kotlinx-serialization = "1.6.2" +ktor = "2.3.7" +bitcoinkmp = "0.20.0" # when upgrading bitcoin-kmp, keep secpjnijvm in sync! +secpjnijvm = "0.15.0" +kermit = "2.0.2" +slf4j = "1.7.36" + +# test dependencies +test-kodein-memory = "0.12.0" +test-bouncycastle = "1.64" +test-logback = "1.2.3" +test-sqlitejdbc = "3.32.3.3" + +[plugins] +multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +dokka = { id = "org.jetbrains.dokka", version = "1.9.10" } diff --git a/modules/core/build.gradle.kts b/modules/core/build.gradle.kts index 74cd0cc3f..51351b91c 100644 --- a/modules/core/build.gradle.kts +++ b/modules/core/build.gradle.kts @@ -4,26 +4,15 @@ import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTes import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest plugins { - kotlin("multiplatform") version "1.9.23" - kotlin("plugin.serialization") version "1.9.23" - id("org.jetbrains.dokka") version "1.9.10" + alias(libs.plugins.multiplatform) + alias(libs.plugins.serialization) + alias(libs.plugins.dokka) `maven-publish` } val currentOs = org.gradle.internal.os.OperatingSystem.current() kotlin { - - val bitcoinKmpVersion = "0.20.0" // when upgrading bitcoin-kmp, keep secpJniJvmVersion in sync! - val secpJniJvmVersion = "0.15.0" - - val serializationVersion = "1.6.2" - val coroutineVersion = "1.7.3" - val datetimeVersion = "0.6.0" - val ktorVersion = "2.3.7" - fun ktor(module: String) = "io.ktor:ktor-$module:$ktorVersion" - val kermitLoggerVersion = "2.0.2" - jvm { compilations.all { kotlinOptions.jvmTarget = "1.8" @@ -67,20 +56,20 @@ kotlin { sourceSets { commonMain { dependencies { - api("fr.acinq.bitcoin:bitcoin-kmp:$bitcoinKmpVersion") - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion") - api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion") - api("org.jetbrains.kotlinx:kotlinx-serialization-cbor:$serializationVersion") - api("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion") - api("org.jetbrains.kotlinx:kotlinx-datetime:$datetimeVersion") - api("co.touchlab:kermit:$kermitLoggerVersion") - api(ktor("network")) - api(ktor("network-tls")) - implementation(ktor("client-core")) - implementation(ktor("client-auth")) - implementation(ktor("client-json")) - implementation(ktor("client-content-negotiation")) - implementation(ktor("serialization-kotlinx-json")) + api("fr.acinq.bitcoin:bitcoin-kmp:${libs.versions.bitcoinkmp.get()}") + api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${libs.versions.kotlinx.coroutines.get()}") + api("org.jetbrains.kotlinx:kotlinx-serialization-core:${libs.versions.kotlinx.serialization.get()}") + api("org.jetbrains.kotlinx:kotlinx-serialization-cbor:${libs.versions.kotlinx.serialization.get()}") + api("org.jetbrains.kotlinx:kotlinx-serialization-json:${libs.versions.kotlinx.serialization.get()}") + api("org.jetbrains.kotlinx:kotlinx-datetime:${libs.versions.kotlinx.datetime.get()}") + api("co.touchlab:kermit:${libs.versions.kermit.get()}") + api("io.ktor:ktor-network:${libs.versions.ktor.get()}") + api("io.ktor:ktor-network-tls:${libs.versions.ktor.get()}") + api("io.ktor:ktor-client-core:${libs.versions.ktor.get()}") + api("io.ktor:ktor-client-auth:${libs.versions.ktor.get()}") + api("io.ktor:ktor-client-json:${libs.versions.ktor.get()}") + api("io.ktor:ktor-client-content-negotiation:${libs.versions.ktor.get()}") + api("io.ktor:ktor-serialization-kotlinx-json:${libs.versions.ktor.get()}") } } @@ -88,43 +77,43 @@ kotlin { dependencies { implementation(kotlin("test-common")) implementation(kotlin("test-annotations-common")) - implementation("org.kodein.memory:klio-files:0.12.0") + implementation("org.kodein.memory:klio-files:${libs.versions.test.kodein.memory.get()}") } } jvmMain { dependencies { - api(ktor("client-okhttp")) - implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:$secpJniJvmVersion") - implementation("org.slf4j:slf4j-api:1.7.36") + api("io.ktor:ktor-client-okhttp:${libs.versions.ktor.get()}") + implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:${libs.versions.secpjnijvm.get()}") + implementation("org.slf4j:slf4j-api:${libs.versions.slf4j.get()}") } } jvmTest { dependencies { implementation(kotlin("test-junit")) - implementation("org.bouncycastle:bcprov-jdk15on:1.64") - implementation("ch.qos.logback:logback-classic:1.2.3") - implementation("org.xerial:sqlite-jdbc:3.32.3.3") + implementation("org.bouncycastle:bcprov-jdk15on:${libs.versions.test.bouncycastle.get()}") + implementation("ch.qos.logback:logback-classic:${libs.versions.test.logback.get()}") + implementation("org.xerial:sqlite-jdbc:${libs.versions.test.sqlitejdbc.get()}") } } if (currentOs.isMacOsX) { iosMain { dependencies { - implementation(ktor("client-ios")) + api("io.ktor:ktor-client-ios:${libs.versions.ktor.get()}") } } macosMain { dependencies { - implementation(ktor("client-darwin")) + api("io.ktor:ktor-client-darwin:${libs.versions.ktor.get()}") } } } linuxMain { dependencies { - implementation(ktor("client-curl")) + api("io.ktor:ktor-client-curl:${libs.versions.ktor.get()}") } }