I'm trying to find a way to share a dependency's version across multiple Version Catalog toml files.
For example, say I have the following two Version Catalog toml files:
libs.versions.toml
[versions]
dagger = "2.42"
[libraries]
dagger-android = { module = "com.google.dagger:dagger-android", version.ref = "dagger" }
buildLibs.versions.toml
[versions]
dagger = "2.42"
[libraries]
hiltAndroidGradlePlugin = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "dagger" }
I use the same dagger
version across both Version Catalogs, and when I need to bump the dagger
version I have to remember to update all toml files.
My workaround is to share the version using the Version Catalog builder API by doing:
In my settings.gradle
ext.sharedVersions = [ dagger : "2.42"]
dependencyResolutionManagement {
versionCatalogs {
libs {
version('dagger', sharedVersions.dagger)
library('dagger-android', 'com.google.dagger', 'dagger-android').versionRef('dagger')
}
buildLibs {
version('dagger', sharedVersions.dagger)
library('hiltAndroidGradlePlugin', 'com.google.dagger', 'hilt-android-gradle-plugin').versionRef('dagger')
}
}
}
which works, but takes away from my dependencies being centralized as some are declared in toml files, while other are declared in settings.gradle
.
CodePudding user response:
As of now, the Version Catalog Builder API is the recommended solution.
https://discuss.gradle.org/t/share-dependency-versions-across-multiple-version-catalogs/43145