# Detect if dependency comes from a version catalog

**URL:** <https://discuss.gradle.org/t/detect-if-dependency-comes-from-a-version-catalog/50641>\
**Category:** Help/Discuss\
**Created:** [March 12, 2025, 6:16pm UTC](https://discuss.gradle.org/t/detect-if-dependency-comes-from-a-version-catalog/50641 "2025-03-12T18:16:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlv](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/dlv/32/11532_2.png) [@dlv](https://discuss.gradle.org/u/dlv)\
**Post date:** [March 12, 2025, 6:16pm UTC](https://discuss.gradle.org/t/detect-if-dependency-comes-from-a-version-catalog/50641/1 "2025-03-12T18:16:49Z")

</div>

I’d like to write a plugin to enforce a rule within our project that any dependency that is available in our Gradle version catalog must be declared using the version catalog.

For example, it should throw an error on this:

```gradle
dependencies {
    implementation 'com.google.guava:guava:32.1.2-jre'
}

```

And then we want to allow:

```gradle
dependencies {
    implementation libs.guava.core
}

```

The main difficulty that I’m hitting is that when I look at the `ModuleDependency` objects in `DependencySet`, I do not see any way to detect if the dependency comes from the version catalog or not. I get normal `name` and `group` values.

How can I tell if a dependency is declared using the version catalog or the standard notation?

---

<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:** [March 14, 2025, 12:03am UTC](https://discuss.gradle.org/t/detect-if-dependency-comes-from-a-version-catalog/50641/2 "2025-03-14T00:03:17Z")

</div>

I don’t think you can.  
At least I’m not aware of a way, not at runtime.  
Only using some static code analysis maybe.
