From 91bb66ece4b0993a2afeb2760650b00d98c93630 Mon Sep 17 00:00:00 2001 From: Alexey Rochev Date: Mon, 29 Jan 2024 01:21:22 +0300 Subject: [PATCH] Move dependency definitions to version catalog --- build.gradle.kts | 106 ++++++++++++---------- gradle/libs.versions.toml | 77 ++++++++++++++++ libs/redreader-common/build.gradle.kts | 18 ++-- libs/redreader-datamodel/build.gradle.kts | 12 ++- 4 files changed, 154 insertions(+), 59 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/build.gradle.kts b/build.gradle.kts index 278c53b70..6300e9235 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,63 +1,75 @@ @file:Suppress("UnstableApiUsage") plugins { - id("com.android.application") version "8.2.2" - kotlin("android") version "1.9.22" - kotlin("plugin.serialization") version "1.9.22" - kotlin("plugin.parcelize") version "1.9.22" + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.kotlin.parcelize) pmd checkstyle + + // If plugin is used in multiple subprojects then it needs to be imported with apply(false) in the root project, + // otherwise bad things will happen. + // The reason is that Gradle isolates class loaders between subprojects and some plugins can't handle it. + // Root project's class loader however is available to all subprojects and importing plugin here (but not applying it) solves the issue + alias(libs.plugins.kotlin.jvm) apply false } dependencies { - - implementation("androidx.multidex:multidex:2.0.1") + implementation(libs.androidx.multidex) implementation(project(":redreader-common")) implementation(project(":redreader-datamodel")) - coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4") - implementation("androidx.core:core-ktx:1.9.0") - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3") - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.6.3") - implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.22") // TODO use constant - implementation("androidx.annotation:annotation:1.7.1") - implementation("androidx.appcompat:appcompat:1.6.1") - implementation("androidx.recyclerview:recyclerview:1.3.2") - implementation("com.google.android.flexbox:flexbox:3.0.0") - implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") - implementation("androidx.preference:preference:1.2.1") - implementation("com.google.android.material:material:1.9.0") - implementation("androidx.constraintlayout:constraintlayout:2.1.4") - implementation("androidx.fragment:fragment:1.6.2") - - implementation("com.fasterxml.jackson.core:jackson-core:2.16.1") - implementation("org.apache.commons:commons-lang3:3.14.0") - - implementation("org.apache.commons:commons-text:1.11.0") - - implementation("com.squareup.okhttp3:okhttp:3.12.13") - implementation("info.guardianproject.netcipher:netcipher-webkit:2.1.0") - implementation("com.google.android.exoplayer:exoplayer-core:2.19.0") - implementation("com.google.android.exoplayer:exoplayer-ui:2.19.0") - implementation("com.github.luben:zstd-jni:1.5.5-11@aar") - - testImplementation("junit:junit:4.13.2") - - androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") - androidTestImplementation("androidx.test:rules:1.5.0") - androidTestImplementation("androidx.test.espresso:espresso-contrib:3.5.1") + coreLibraryDesugaring(libs.jdk.desugar) + + implementation(libs.kotlinx.serialization.json) + implementation(libs.kotlinx.serialization.json.okio) + implementation(libs.kotlin.reflect) + + implementation(libs.androidx.annotation) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.core) + implementation(libs.androidx.fragment) + implementation(libs.androidx.preference) + implementation(libs.androidx.recyclerview) + implementation(libs.androidx.swiperefreshlayout) + + implementation(libs.google.flexbox) + implementation(libs.google.material) + + implementation(libs.jackson.core) + implementation(libs.commons.lang) + + implementation(libs.commons.text) + + implementation(libs.okhttp) + implementation(libs.netcipher.webkit) + implementation(libs.exoplayer.core) + implementation(libs.exoplayer.ui) + implementation(libs.zstd) { + artifact { + type = "aar" + } + } + + testImplementation(libs.junit) + + androidTestImplementation(libs.androidx.test.espresso.core) + androidTestImplementation(libs.androidx.test.espresso.contrib) + androidTestImplementation(libs.androidx.test.rules) } android { - compileSdk = 33 - ndkVersion = "23.1.7779620" + compileSdk = libs.versions.sdk.compile.get().toInt() + ndkVersion = libs.versions.ndk.get() namespace = "org.quantumbadger.redreader" defaultConfig { applicationId = "org.quantumbadger.redreader" - minSdk = 16 - targetSdk = 33 + minSdk = libs.versions.sdk.min.get().toInt() + targetSdk = libs.versions.sdk.target.get().toInt() versionCode = 112 versionName = "1.23.1" @@ -81,8 +93,10 @@ android { compileOptions { encoding = "UTF-8" isCoreLibraryDesugaringEnabled = true - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + JavaVersion.toVersion(libs.versions.java.get()).let { + sourceCompatibility = it + targetCompatibility = it + } } lint { @@ -105,7 +119,7 @@ android { } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = libs.versions.java.get() } buildFeatures { @@ -114,7 +128,7 @@ android { } pmd { - toolVersion = "6.55.0" + toolVersion = libs.versions.pmd.get() } tasks.register("pmd", Pmd::class) { @@ -127,7 +141,7 @@ tasks.register("pmd", Pmd::class) { } checkstyle { - toolVersion = "10.12.5" + toolVersion = libs.versions.checkstyle.get() } tasks.register("Checkstyle", Checkstyle::class) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..175b54775 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,77 @@ +[versions] +agp = "8.2.2" +kotlin = "1.9.22" +java = "1.8" + +sdk-compile = "33" +sdk-min = "16" +sdk-target = "33" +ndk = "23.1.7779620" + +androidx-annotation = "1.7.1" +androidx-appcompat = "1.6.1" +androidx-constraintlayout = "2.1.4" +androidx-core = "1.9.0" +androidx-fragment = "1.6.2" +androidx-multidex = "2.0.1" +androidx-preference = "1.2.1" +androidx-recyclerview = "1.3.2" +androidx-swiperefreshlayout = "1.1.0" + +checkstyle = "10.12.5" +commons-lang = "3.14.0" +commons-text = "1.11.0" +exoplayer = "2.19.0" +google-flexbox = "3.0.0" +google-material = "1.9.0" +jackson = "2.16.1" +jdk-desugar = "2.0.4" +kotlinx-datetime = "0.5.0" +kotlinx-serialization = "1.6.3" +netcipher = "2.1.0" +okhttp = "3.12.13" +pmd = "6.55.0" +zstd = "1.5.5-11" + +junit = "4.13.2" +androidx-test-espresso = "3.5.1" +androidx-test-rules = "1.5.0" + +[libraries] +androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" } +androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } +androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" } +androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidx-core" } +androidx-fragment = { module = "androidx.fragment:fragment", version.ref = "androidx-fragment" } +androidx-multidex = { module = "androidx.multidex:multidex", version.ref = "androidx-multidex" } +androidx-preference = { module = "androidx.preference:preference", version.ref = "androidx-preference" } +androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidx-recyclerview" } +androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "androidx-swiperefreshlayout" } + +commons-lang = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang" } +commons-text = { module = "org.apache.commons:commons-text", version.ref = "commons-text" } +exoplayer-core = { module = "com.google.android.exoplayer:exoplayer-core", version.ref = "exoplayer" } +exoplayer-ui = { module = "com.google.android.exoplayer:exoplayer-ui", version.ref = "exoplayer" } +google-flexbox = { module = "com.google.android.flexbox:flexbox", version.ref = "google-flexbox" } +google-material = { module = "com.google.android.material:material", version.ref = "google-material" } +jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" } +jdk-desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "jdk-desugar" } +kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } +kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } +kotlinx-serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "kotlinx-serialization" } +netcipher-webkit = { module = "info.guardianproject.netcipher:netcipher-webkit", version.ref = "netcipher" } +okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } +zstd = { module = "com.github.luben:zstd-jni", version.ref = "zstd" } + +junit = { module = "junit:junit", version.ref = "junit" } +androidx-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-test-espresso" } +androidx-test-espresso-contrib = { module = "androidx.test.espresso:espresso-contrib", version.ref = "androidx-test-espresso" } +androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidx-test-rules" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } diff --git a/libs/redreader-common/build.gradle.kts b/libs/redreader-common/build.gradle.kts index 9e171b0b5..f546c24fe 100644 --- a/libs/redreader-common/build.gradle.kts +++ b/libs/redreader-common/build.gradle.kts @@ -8,21 +8,23 @@ buildscript { } plugins { - id("java-library") - id("org.jetbrains.kotlin.jvm") - kotlin("plugin.serialization") version("1.9.22") apply(true) + `java-library` + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.serialization) } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + JavaVersion.toVersion(libs.versions.java.get()).let { + sourceCompatibility = it + targetCompatibility = it + } } tasks.withType(KotlinJvmCompile::class) { - kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() + kotlinOptions.jvmTarget = libs.versions.java.get() } dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0") - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3") + implementation(libs.kotlinx.datetime) + implementation(libs.kotlinx.serialization.json) } diff --git a/libs/redreader-datamodel/build.gradle.kts b/libs/redreader-datamodel/build.gradle.kts index 9a6eb8ee5..97c144363 100644 --- a/libs/redreader-datamodel/build.gradle.kts +++ b/libs/redreader-datamodel/build.gradle.kts @@ -1,17 +1,19 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile plugins { - id("java-library") - id("org.jetbrains.kotlin.jvm") + `java-library` + alias(libs.plugins.kotlin.jvm) } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + JavaVersion.toVersion(libs.versions.java.get()).let { + sourceCompatibility = it + targetCompatibility = it + } } tasks.withType(KotlinJvmCompile::class) { - kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() + kotlinOptions.jvmTarget = libs.versions.java.get() } dependencies {