# Share dependency versions across multiple Version Catalogs

**URL:** <https://discuss.gradle.org/t/share-dependency-versions-across-multiple-version-catalogs/43145>\
**Category:** Help/Discuss\
**Created:** [June 15, 2022, 10:53pm UTC](https://discuss.gradle.org/t/share-dependency-versions-across-multiple-version-catalogs/43145 "2022-06-15T22:53:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanalvarado](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ivanalvarado/32/9866_2.png) [@ivanalvarado](https://discuss.gradle.org/u/ivanalvarado)\
**Post date:** [June 15, 2022, 10:53pm UTC](https://discuss.gradle.org/t/share-dependency-versions-across-multiple-version-catalogs/43145/1 "2022-06-15T22:53:53Z")

</div>

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`

```nohighlight
[versions]
dagger = "2.42"

[libraries]
dagger-android = { module = "com.google.dagger:dagger-android", version.ref = "dagger" }

```

`buildLibs.versions.toml`

```nohighlight
[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`

```groovy
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`.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [June 16, 2022, 5:06pm UTC](https://discuss.gradle.org/t/share-dependency-versions-across-multiple-version-catalogs/43145/2 "2022-06-16T17:06:35Z")

</div>

There might not be a way with TOML files.  
They are intentionally just for the simple cases.  
And for more complex use-cases the programmatic API is intended.  
You could maybe also have a settings plugin that defines it or similar.

Btw. if you keep the current way, please at least do not use `ext` but just a local variable with `def`.  
Almost any usage of `ext` is just a dirty work-around that should be replaced by something more appropriate like a local variable or a properly typed extension.
