# Trouble using centralized dependency versions in buildSrc plugins and buildscript classpath

**URL:** <https://discuss.gradle.org/t/trouble-using-centralized-dependency-versions-in-buildsrc-plugins-and-buildscript-classpath/39421>\
**Category:** Help/Discuss\
**Created:** [March 25, 2021, 12:06pm UTC](https://discuss.gradle.org/t/trouble-using-centralized-dependency-versions-in-buildsrc-plugins-and-buildscript-classpath/39421 "2021-03-25T12:06:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![neu242](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/neu242/32/5722_2.png) [@neu242](https://discuss.gradle.org/u/neu242)\
**Post date:** [March 25, 2021, 12:06pm UTC](https://discuss.gradle.org/t/trouble-using-centralized-dependency-versions-in-buildsrc-plugins-and-buildscript-classpath/39421/1 "2021-03-25T12:06:28Z")

</div>

The new [centralized dependency versions](https://docs.gradle.org/7.0-rc-1/release-notes.html#centralized-versions) feature preview in Gradle 7 is pretty great, but there are a couple of places where `libs` doesn’t resolve.

1. In plugins in buildSrc, e.g. `buildSrc/src/main/kotlin/MyPlugin.kt`:

2. In `dependencies/classpath` in the root `build.gradle.kts`:

3. In the root `settings.gradle.kts`:

4. In the plugins block in `buildSrc/build.gradle.kts`:

Is there a way to solve any of these?

SEO: `enableFeaturePreview("VERSION_CATALOGS")`

---

<div class="post-metadata">

**Author:** ![CedricChampeau](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/cedricchampeau/32/7541_2.png) [@CedricChampeau](https://discuss.gradle.org/u/CedricChampeau)\
**Post date:** [March 26, 2021, 3:54pm UTC](https://discuss.gradle.org/t/trouble-using-centralized-dependency-versions-in-buildsrc-plugins-and-buildscript-classpath/39421/2 "2021-03-26T15:54:30Z")

</div>

Hi @neu242 !

1. 

You can’t use _type-safe_ catalogs in plugins, for the reason explained in this ticket: [Make version catalogs accessible from precompiled script plugins · Issue #15383 · gradle/gradle · GitHub](https://github.com/gradle/gradle/issues/15383)

Basically if you use `libs` in a plugin, precompiled or not, we have to assume that it’s going to be applied to a project which has _exactly the same model_, which might not be the case.

There is, however, a “type-unsafe” API to access the catalogs: [Provide access to version catalogs from plugins by melix · Pull Request #15443 · gradle/gradle · GitHub](https://github.com/gradle/gradle/pull/15443/files#diff-5e341d2605a36e31ef4c643790effcdbbf1d4ca23483da374e04aeb3781d4e87R1025)

1. buildscript blocks as well as the plugins block are evaluated _before_ the project extensions are loaded, so _before_ the catalogs are available. It’s not possible yet to use catalogs for this purpose. The initial implementation to support versions in plugins has been removed, but we’re planning more work on this.

2. the `settings` file is the one loading/defining catalogs. This means that the plugins of the settings file itself _cannot_ use catalogs, because they are not available yet. Chicken and egg problem.

3. same problem here

---

<div class="post-metadata">

**Author:** ![neu242](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/neu242/32/5722_2.png) [@neu242](https://discuss.gradle.org/u/neu242)\
**Post date:** [March 26, 2021, 4:07pm UTC](https://discuss.gradle.org/t/trouble-using-centralized-dependency-versions-in-buildsrc-plugins-and-buildscript-classpath/39421/3 "2021-03-26T16:07:52Z")

</div>

Hi @CedricChampeau 🙂

This makes sense. Thanks for the solution to (1). This seems to work:

```gradle
fun libs(lib: String) =
  project.extensions.getByType(VersionCatalogsExtension::class).named("libs").findDependency(lib).get()

dependencies {
  implementation(libs("gson"))
}

```

Looking forward to a solution to (2) as well.

And thanks for great answers!
