Skip to content

Commit

Permalink
Manage dependencies with a version catalog (#727)
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
pm47 authored Nov 27, 2024
1 parent 6cc534c commit 49ed521
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
21 changes: 21 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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" }
65 changes: 27 additions & 38 deletions modules/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -67,64 +56,64 @@ 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()}")
}
}

commonTest {
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()}")
}
}

Expand Down

0 comments on commit 49ed521

Please sign in to comment.