Use Gradle version catalog to simplify dependencies (#10938)

* Use Gradle version catalog to simplify dependencies

* Changes based on review comments
This commit is contained in:
Andreas 2022-02-27 15:49:41 +01:00 committed by GitHub
parent ef2c7c761d
commit c83960aaef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 77 additions and 71 deletions

View File

@ -108,7 +108,7 @@ Extensions rely on [extensions-lib](https://github.com/tachiyomiorg/extensions-l
```gradle ```gradle
dependencies { dependencies {
implementation project(':lib-ratelimit') implementation(project(':lib-ratelimit'))
} }
``` ```
@ -118,7 +118,7 @@ dependencies {
```gradle ```gradle
dependencies { dependencies {
implementation project(':lib-dataimage') implementation(project(':lib-dataimage'))
} }
``` ```
@ -130,12 +130,12 @@ For example, an extension that needs coroutines, it could add the following:
```gradle ```gradle
dependencies { dependencies {
compileOnly 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2' compileOnly(libs.bundles.coroutines)
compileOnly 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
} }
``` ```
(Note that several dependencies are already exposed to all extensions via `common-dependencies.gradle`.) > Note that several dependencies are already exposed to all extensions via Gradle version catalog.
> To view which are available view `libs.versions.toml` under the `gradle` folder
Notice that we're using `compileOnly` instead of `implementation`, since the app already contains it. You could use `implementation` instead for a new dependency, or you prefer not to rely on whatever the main app has at the expense of app size. Notice that we're using `compileOnly` instead of `implementation`, since the app already contains it. You could use `implementation` instead for a new dependency, or you prefer not to rely on whatever the main app has at the expense of app size.

View File

@ -1,27 +0,0 @@
buildscript {
ext.kotlin_version = '1.4.32'
ext.coroutines_version = '1.4.3'
repositories {
mavenCentral()
google()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath 'org.jmailen.gradle:kotlinter-gradle:3.4.0'
}
}
allprojects {
repositories {
mavenCentral()
google()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

27
build.gradle.kts Normal file
View File

@ -0,0 +1,27 @@
buildscript {
repositories {
mavenCentral()
google()
maven(url = "https://plugins.gradle.org/m2/")
}
dependencies {
val libs = project.extensions.getByType<VersionCatalogsExtension>()
.named("libs") as org.gradle.accessors.dm.LibrariesForLibs
classpath(libs.gradle.agp)
classpath(libs.gradle.kotlin)
classpath(libs.gradle.serialization)
classpath(libs.gradle.kotlinter)
}
}
allprojects {
repositories {
mavenCentral()
google()
maven(url = "https://jitpack.io")
}
}
tasks.register<Delete>("clean") {
delete(rootProject.buildDir)
}

View File

@ -1,9 +0,0 @@
object Dependencies {
object kotlin {
const val version = "1.4.32"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
}
const val jsoup = "org.jsoup:jsoup:1.13.1"
const val okhttp = "com.squareup.okhttp3:okhttp:4.9.1"
}

View File

@ -1,15 +0,0 @@
// used both in common.gradle and themesources library
dependencies {
// Lib 1.2, but using specific commit so we don't need to bump up the version
compileOnly "com.github.tachiyomiorg:extensions-lib:58b2d3a"
// These are provided by the app itself
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compileOnly 'com.github.inorichi.injekt:injekt-core:65b0440'
compileOnly 'com.squareup.okhttp3:okhttp:4.9.1'
compileOnly 'io.reactivex:rxjava:1.3.8'
compileOnly 'org.jsoup:jsoup:1.13.1'
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.2.0'
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.0'
}

View File

@ -88,9 +88,9 @@ repositories {
} }
dependencies { dependencies {
implementation project(":core") implementation(project(":core"))
compileOnly(libs.bundles.common)
} }
apply from: "$rootDir/common-dependencies.gradle"
preBuild.dependsOn(lintKotlin) preBuild.dependsOn(lintKotlin)
lintKotlin.dependsOn(formatKotlin) lintKotlin.dependsOn(formatKotlin)

29
gradle/libs.versions.toml Normal file
View File

@ -0,0 +1,29 @@
[versions]
kotlin_version = "1.4.32"
coroutines_version = "1.4.3"
[libraries]
gradle-agp = { module = "com.android.tools.build:gradle", version = "4.2.1" }
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin_version" }
gradle-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin_version" }
gradle-kotlinter = { module = "org.jmailen.gradle:kotlinter-gradle", version = "3.4.0" }
tachiyomi-lib = { module = "com.github.tachiyomiorg:extensions-lib", version = "58b2d3a" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin_version" }
kotlin-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version = "1.2.0" }
kotlin-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.2.0" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines_version" }
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines_version" }
injekt-core = { module = "com.github.inorichi.injekt:injekt-core", version = "65b0440" }
jsoup = { module = "org.jsoup:jsoup", version = "1.13.1" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version = "4.9.1" }
rxandroid = { module = "io.reactivex:rxandroid", version = "1.2.1" }
rxjava = { module = "io.reactivex:rxjava", version = "1.3.8" }
[bundles]
common = ["tachiyomi-lib", "jsoup", "okhttp", "kotlin-stdlib", "injekt-core", "rxjava", "kotlin-protobuf", "kotlin-json"]
coroutines = ["coroutines-core", "coroutines-android"]
reactivex = ["rxandroid"]

View File

@ -17,7 +17,7 @@ repositories {
} }
dependencies { dependencies {
compileOnly(Dependencies.kotlin.stdlib) compileOnly(libs.kotlin.stdlib)
compileOnly(Dependencies.okhttp) compileOnly(libs.okhttp)
compileOnly(Dependencies.jsoup) compileOnly(libs.jsoup)
} }

View File

@ -17,6 +17,6 @@ repositories {
} }
dependencies { dependencies {
compileOnly(Dependencies.kotlin.stdlib) compileOnly(libs.kotlin.stdlib)
compileOnly(Dependencies.okhttp) compileOnly(libs.okhttp)
} }

View File

@ -20,18 +20,19 @@ repositories {
mavenCentral() mavenCentral()
} }
// dependencies dependencies {
apply("$rootDir/common-dependencies.gradle") compileOnly(libs.bundles.common)
}
tasks { tasks {
val generateExtensions by registering { val generateExtensions by registering {
doLast { doLast {
val isWindows = System.getProperty("os.name").toString().toLowerCase().contains("win") val isWindows = System.getProperty("os.name").toString().toLowerCase().contains("win")
var classPath = (configurations.debugCompileOnly.get().asFileTree.toList() + var classPath = (configurations.debugCompileOnly.get().asFileTree.toList() +
listOf( listOf(
configurations.androidApis.get().asFileTree.first().absolutePath, // android.jar path configurations.androidApis.get().asFileTree.first().absolutePath, // android.jar path
"$projectDir/build/intermediates/aar_main_jar/debug/classes.jar" // jar made from this module "$projectDir/build/intermediates/aar_main_jar/debug/classes.jar" // jar made from this module
)) ))
.joinToString(if (isWindows) ";" else ":") .joinToString(if (isWindows) ";" else ":")
var javaPath = "${System.getProperty("java.home")}/bin/java" var javaPath = "${System.getProperty("java.home")}/bin/java"

View File

@ -1,3 +1,5 @@
enableFeaturePreview("VERSION_CATALOGS")
include(":core") include(":core")
include(":lib-ratelimit") include(":lib-ratelimit")

View File

@ -10,8 +10,7 @@ ext {
} }
dependencies { dependencies {
compileOnly 'io.reactivex:rxandroid:1.2.1' compileOnly libs.bundles.reactivex
compileOnly 'io.reactivex:rxjava:1.3.8'
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -10,8 +10,7 @@ ext {
} }
dependencies { dependencies {
compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" compileOnly libs.bundles.coroutines
compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation project(':lib-ratelimit') implementation project(':lib-ratelimit')
} }