I want to use centralized dependency versions intr...
# gradle
j
I want to use centralized dependency versions introduced in Gradle 7 (https://docs.gradle.org/7.0/release-notes.html#centralized-versions), which works fine so far. Can I use the dependency declared in a toml file within a Custom Gradle Plugin?
v
Not how you probably intend it, at least not easily. But to say that for sure you have to provide more information. Where do you declare the catalog, where do you have the plugin, how do you want to use it, ...
j
I have an android project with many gradle modules. I have a Gradle Plugin which is included in every module. It sets up various things to prevent declaring them in every module. Besides Android specific stuff I also include dependencies which belong to every module. I wonder if I can retrieve these from the toml file/version catalog as well 💭
v
Can you become a bit more concrete and less abstract in terms of files? What is your file structure? In which file is the catalog defined? Is this a plugin you want to release separately (even internal) and use as dependency? Is this just a local convention plugin in
buildSrc
or an included build in the same project? ...?
j
Ah yes the latter. Just a Plugin for my project in the
buildSrc
file. I defined the catalog in that project within a
toml
file
I tried to add the catalog to the buildSrc as mentioned in the documentation in the
settings.gradle.kts
file:
Copy code
dependencyResolutionManagement {
    versionCatalogs {
        create("lib") {
            from(files("../gradle/libs.versions.toml"))
        }
    }
}
v
You can either use the non-typesafe String based API using the
VersionCatalogsExtension
. This is the currently supported "official" way. For that you also do not define the catalog in the
buildSrc
settings script, except if you also use it in the build scripts there. If you want to use the generated accessors, there is a hacky work-around at https://github.com/gradle/gradle/issues/15383
j
I guess as long as I don’t have to specify the dependency versions a String based API sounds awesome \o/
Ah I guess in the end it’s this issue: https://github.com/gradle/gradle/issues/16958 I’ll follow with the workaround for now and Keep an eye on that. Thanks for the help @Vampire
v
Sounds more like the issue I linked you to and the workaround in #16958 is probably based on mine. 😄 But whatever works for you.