From 5ba1f34dccfa9bc379c446fc2818bbee75e97ec2 Mon Sep 17 00:00:00 2001 From: "Kenneth J. Shackleton" Date: Tue, 23 Apr 2024 08:05:46 +0100 Subject: [PATCH] Move dependency versions to a libs.versions.toml catalogue. Signed-off-by: Kenneth J. Shackleton --- AndroidCLI/build.gradle.kts | 10 +++--- AndroidLibBenchmark/build.gradle.kts | 21 ++++++------ SQLite3/build.gradle.kts | 2 +- build.gradle.kts | 6 ++-- buildSrc/build.gradle.kts | 7 ++-- buildSrc/settings.gradle.kts | 8 +++++ buildSrc/src/main/kotlin/SelektExtensions.kt | 4 --- buildSrc/src/main/kotlin/Versions.kt | 10 ------ gradle/libs.versions.toml | 36 ++++++++++++++++++++ selekt-android-lint/build.gradle.kts | 6 ++-- selekt-android-sqlcipher/build.gradle.kts | 2 +- selekt-android/build.gradle.kts | 17 +++++---- selekt-java/build.gradle.kts | 2 +- 13 files changed, 78 insertions(+), 53 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/AndroidCLI/build.gradle.kts b/AndroidCLI/build.gradle.kts index c3fa58ed93..3919e7fa15 100644 --- a/AndroidCLI/build.gradle.kts +++ b/AndroidCLI/build.gradle.kts @@ -28,7 +28,7 @@ repositories { android { compileSdk = Versions.ANDROID_SDK.version.toInt() - buildToolsVersion = Versions.ANDROID_BUILD_TOOLS.version + buildToolsVersion = libs.android.tools.gradle.get().version!! namespace = "com.bloomberg.selekt.cli" defaultConfig { applicationId = "com.bloomberg.selekt.cli" @@ -59,9 +59,9 @@ android { dependencies { implementation(projects.selektAndroid) - implementation(androidX("appcompat", version = "1.0.2")) - implementation(androidX("core", "ktx", version = "1.0.2")) - implementation(androidX("paging", "runtime", "2.1.0")) - implementation(androidX("constraintlayout", version = "1.1.3")) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.paging) runtimeOnly(projects.selektAndroidSqlcipher) } diff --git a/AndroidLibBenchmark/build.gradle.kts b/AndroidLibBenchmark/build.gradle.kts index bceeeea131..50c64a0021 100644 --- a/AndroidLibBenchmark/build.gradle.kts +++ b/AndroidLibBenchmark/build.gradle.kts @@ -17,7 +17,7 @@ plugins { id("com.android.library") id("kotlin-android") - id("androidx.benchmark") version Versions.ANDROID_BENCHMARK.version + id("androidx.benchmark") version libs.androidx.benchmark.get().version id("io.gitlab.arturbosch.detekt") id("org.jlleitschuh.gradle.ktlint") } @@ -29,7 +29,7 @@ repositories { android { compileSdkVersion(Versions.ANDROID_SDK.version.toInt()) - buildToolsVersion(Versions.ANDROID_BUILD_TOOLS.version) + buildToolsVersion(libs.android.tools.gradle.get().version!!) namespace = "com.bloomberg.selekt.android.benchmark" defaultConfig { minSdkVersion(21) @@ -49,13 +49,12 @@ android { dependencies { androidTestImplementation(projects.selektAndroid) - androidTestImplementation("junit:junit:${Versions.JUNIT4}") - androidTestImplementation("androidx.test:runner:1.5.2") - androidTestImplementation("androidx.test:rules:1.5.0") - androidTestImplementation("androidx.test.ext:junit:1.1.5") - androidTestImplementation(androidX("benchmark", "junit4", Versions.ANDROID_BENCHMARK.version)) - androidTestImplementation(kotlin("test", Versions.KOTLIN.version)) - androidTestImplementation(kotlin("test-junit", Versions.KOTLIN.version)) - androidTestImplementation(kotlinX("coroutines-core", Versions.KOTLINX_COROUTINES.version)) - testImplementation(kotlinX("coroutines-core", Versions.KOTLINX_COROUTINES.version)) + androidTestImplementation(libs.androidx.benchmark) + androidTestImplementation(libs.androidx.test.rules) + androidTestImplementation(libs.androidx.test.runner) + androidTestImplementation(libs.junit.junit) + androidTestImplementation(libs.kotlin.test) + androidTestImplementation(libs.kotlin.test.junit) + androidTestImplementation(libs.kotlinx.coroutines.core) + testImplementation(libs.kotlinx.coroutines.core) } diff --git a/SQLite3/build.gradle.kts b/SQLite3/build.gradle.kts index 4baaa7097d..84e6819788 100644 --- a/SQLite3/build.gradle.kts +++ b/SQLite3/build.gradle.kts @@ -101,7 +101,7 @@ tasks.register("cmakeSQLite") { Files.createDirectories(workingDir) } workingDir(".cxx-host") - commandLine("cmake") + commandLine("/usr/local/mobile/developer/tools/android/android-sdk/cmake/3.22.1/bin/cmake") args( "-DCMAKE_BUILD_TYPE=Release", "-DUSE_CCACHE=1", diff --git a/build.gradle.kts b/build.gradle.kts index 719f8e07b3..5e4a3a1b36 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -86,11 +86,11 @@ subprojects { add(name, "com.google.code.findbugs:jsr305:[2.0.2, ${Versions.JSR_305}]") } configurations.getByName("implementation").apply { - platform(kotlinX("coroutines-bom", version = Versions.KOTLINX_COROUTINES.version)) + add(name, platform(libs.kotlinx.coroutines.bom)) } configurations.getByName("testImplementation") { - add(name, kotlin("test", Versions.KOTLIN_TEST.version)) - add(name, kotlinX("coroutines-core", version = Versions.KOTLINX_COROUTINES.version)) + add(name, libs.kotlin.test) + add(name, libs.kotlinx.coroutines.core) add(name, "org.mockito:mockito-core:${Versions.MOCKITO}") add(name, "org.mockito.kotlin:mockito-kotlin:${Versions.MOCKITO_KOTLIN}") } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 615b5bab04..6c47a90a22 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -14,9 +14,6 @@ * limitations under the License. */ -// TODO Move me. -val kotlinVersion = "1.9.23" - plugins { `kotlin-dsl` `java-gradle-plugin` @@ -37,6 +34,6 @@ gradlePlugin { } dependencies { - implementation(kotlin("gradle-plugin", version = kotlinVersion)) - implementation("com.android.tools.build:gradle:8.3.2") + implementation(kotlin("gradle-plugin", version = libs.versions.kotlin.get())) + implementation(libs.android.tools.gradle) } diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 8fa633c866..57277961a5 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -15,3 +15,11 @@ */ rootProject.name = "buildSrc" + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/SelektExtensions.kt b/buildSrc/src/main/kotlin/SelektExtensions.kt index b3e77635fe..1d99b14bd1 100644 --- a/buildSrc/src/main/kotlin/SelektExtensions.kt +++ b/buildSrc/src/main/kotlin/SelektExtensions.kt @@ -16,7 +16,6 @@ import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project -import org.gradle.api.artifacts.DependencySubstitutions import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.provider.Provider import org.gradle.api.publish.maven.MavenPom @@ -24,9 +23,6 @@ import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.net.URI -fun DependencyHandler.androidX(module: String, suffix: String? = null, version: String? = null): Any = - "androidx.$module:$module${suffix?.let { "-$it" }.orEmpty()}${version?.let { ":$it" }.orEmpty()}" - fun DependencyHandler.kotlinX(module: String, version: String? = null): Any = "org.jetbrains.kotlinx:kotlinx-$module${version?.let { ":$version" }.orEmpty()}" diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 148bb9d846..7e06c977d8 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -20,14 +20,9 @@ enum class Versions( val version: String, private val url: URL ) { - ANDROID_BENCHMARK("1.2.0-alpha13", URL("https://developer.android.com/studio/profile/benchmark")), - ANDROID_BUILD_TOOLS("34.0.0", URL("https://developer.android.com/studio/releases/build-tools")), ANDROID_GRADLE_PLUGIN("8.3.2", URL("https://developer.android.com/tools/revisions/gradle-plugin.html")), - ANDROID_LINT("30.0.2", URL("https://github.com/googlesamples/android-custom-lint-rules")), ANDROID_NDK("26.3.11579264", URL("https://developer.android.com/ndk")), ANDROID_SDK("34", URL("https://developer.android.com/sdk")), - ANDROIDX_LIVE_DATA("2.5.1", URL("https://developer.android.com/topic/libraries/architecture/livedata")), - ANDROIDX_ROOM("2.6.1", URL("https://developer.android.com/jetpack/androidx/releases/room")), CMAKE("3.22.1", URL("https://cmake.org")), DETEKT("1.22.0", URL("https://github.com/arturbosch/detekt")), DOKKA("1.9.10", URL("https://github.com/Kotlin/dokka")), @@ -36,11 +31,6 @@ enum class Versions( IDE_EXT_GRADLE_PLUGIN("1.1.7", URL("https://github.com/JetBrains/gradle-idea-ext-plugin")), JMH("1.36", URL("https://openjdk.java.net/projects/code-tools/jmh/")), JSR_305("3.0.2", URL("https://code.google.com/archive/p/jsr-305/")), - JUNIT4("4.13.2", URL("https://github.com/junit-team/junit4")), - JUNIT5("5.10.2", URL("https://junit.org/junit5/")), - KOTLIN("1.9.23", URL("https://github.com/JetBrains/kotlin")), - KOTLIN_TEST(KOTLIN.version, URL("https://github.com/JetBrains/kotlin")), - KOTLINX_COROUTINES("1.7.3", URL("https://github.com/Kotlin/kotlinx.coroutines")), KOTLINX_KOVER("0.7.6", URL("https://github.com/Kotlin/kotlinx-kover")), KTLINT("0.45.2", URL("https://github.com/pinterest/ktlint")), KTLINT_GRADLE_PLUGIN("11.5.0", URL("https://github.com/JLLeitschuh/ktlint-gradle")), diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000000..29421e0320 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,36 @@ +# https://docs.gradle.org/current/userguide/platforms.html#sub:conventional-dependencies-toml + +[versions] +kotlin = "1.9.23" +room = "2.6.1" + +[libraries] +android-tools-lint = { group = "com.android.tools.lint", name = "lint", version = "30.0.2" } +android-tools-lint-api = { group = "com.android.tools.lint", name = "lint-api", version = "30.0.2" } +android-tools-gradle = { group = "com.android.tools.build", name = "gradle", version = "8.3.0" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version = "1.0.2" } +androidx-benchmark = { group = "androidx.benchmark", name = "benchmark", version = "1.2.0-alpha13" } +androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version = "1.1.3" } +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version = "1.0.2" } +androidx-paging = { group = "androidx.paging", name = "paging-runtime", version = "2.1.0" } +androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version = "2.5.1" } +androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } +androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" } +androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } +androidx-test-ext = { group = "androidx.test.ext", name = "junit", version = "1.1.5" } +androidx-test-rules = { group = "androidx.test", name = "rules", version = "1.5.0" } +androidx-test-runner = { group = "androidx.test", name = "runner", version = "1.5.2" } +junit-junit = { group = "junit", name = "junit", version = "4.13.2" } +junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version = "5.10.2" } +kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin" } +kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" } +kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlin" } +kotlinx-coroutines-bom = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-bom", version = "1.7.3" } +kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core" } +mockito-core = { group = "org.mockito", name = "mockito-core", version = "5.11.0" } +mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version = "5.3.1" } +robolectric-android-all = { group = "org.robolectric", name = "android-all", version = "12.1-robolectric-8229987" } + +[bundles] + +[plugins] diff --git a/selekt-android-lint/build.gradle.kts b/selekt-android-lint/build.gradle.kts index af64605a90..5e9c985fe8 100644 --- a/selekt-android-lint/build.gradle.kts +++ b/selekt-android-lint/build.gradle.kts @@ -33,9 +33,9 @@ java { } dependencies { - compileOnly("com.android.tools.lint:lint:${Versions.ANDROID_LINT}") - compileOnly("com.android.tools.lint:lint-api:${Versions.ANDROID_LINT}") - implementation(kotlin("reflect", Versions.KOTLIN.version)) + compileOnly(libs.android.tools.lint.asProvider()) + compileOnly(libs.android.tools.lint.api) + implementation(libs.kotlin.reflect) } tasks.withType().configureEach { diff --git a/selekt-android-sqlcipher/build.gradle.kts b/selekt-android-sqlcipher/build.gradle.kts index 21fad9fdf8..8856d27eb6 100644 --- a/selekt-android-sqlcipher/build.gradle.kts +++ b/selekt-android-sqlcipher/build.gradle.kts @@ -37,7 +37,7 @@ val allABIs = listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64") android { compileSdk = Versions.ANDROID_SDK.version.toInt() - buildToolsVersion = Versions.ANDROID_BUILD_TOOLS.version + buildToolsVersion = libs.android.tools.gradle.get().version!! namespace = "com.bloomberg.selekt.android.sqlcipher" ndkVersion = Versions.ANDROID_NDK.version defaultConfig { diff --git a/selekt-android/build.gradle.kts b/selekt-android/build.gradle.kts index bb8ffa769f..1ec1d5453c 100644 --- a/selekt-android/build.gradle.kts +++ b/selekt-android/build.gradle.kts @@ -37,8 +37,7 @@ repositories { android { compileSdk = Versions.ANDROID_SDK.version.toInt() - @Suppress("UnstableApiUsage") - buildToolsVersion = Versions.ANDROID_BUILD_TOOLS.version + buildToolsVersion = libs.android.tools.gradle.get().version!! namespace = "com.bloomberg.selekt.android" defaultConfig { minSdk = 21 @@ -62,16 +61,16 @@ android { dependencies { api(projects.selektApi) compileOnly(projects.selektAndroidSqlcipher) - compileOnly(androidX("room", "runtime", Versions.ANDROIDX_ROOM.version)) + compileOnly(libs.androidx.room.runtime) implementation(projects.selektJava) implementation(projects.selektSqlite3Classes) - kaptTest(androidX("room", "compiler", Versions.ANDROIDX_ROOM.version)) - testImplementation(androidX("lifecycle", "livedata-ktx", Versions.ANDROIDX_LIVE_DATA.version)) - testImplementation(androidX("room", "runtime", Versions.ANDROIDX_ROOM.version)) - testImplementation(androidX("room", "ktx", Versions.ANDROIDX_ROOM.version)) - testImplementation("org.junit.jupiter:junit-jupiter-params:${Versions.JUNIT5}") + kaptTest(libs.androidx.room.compiler) + testImplementation(libs.androidx.lifecycle.livedata.ktx) + testImplementation(libs.androidx.room.runtime) + testImplementation(libs.androidx.room.ktx) + testImplementation(libs.junit.jupiter.params) testRuntimeOnly(projects.selektAndroidSqlcipher) - testRuntimeOnly("org.robolectric:android-all:${Versions.ROBOLECTRIC_ANDROID_ALL}") + testRuntimeOnly(libs.robolectric.android.all) } koverReport { diff --git a/selekt-java/build.gradle.kts b/selekt-java/build.gradle.kts index 92b36bfa6a..812e091cea 100644 --- a/selekt-java/build.gradle.kts +++ b/selekt-java/build.gradle.kts @@ -60,7 +60,7 @@ val integrationTestRuntimeOnly: Configuration by configurations.getting { dependencies { implementation(projects.selektApi) implementation(projects.selektSqlite3Classes) - jmhImplementation(kotlinX("coroutines-core", version = Versions.KOTLINX_COROUTINES.version)) + jmhImplementation(libs.kotlinx.coroutines.core) } publishing {