# How can I check for snapshot dependencies and throw an exception if some where found?

**URL:** <https://discuss.gradle.org/t/how-can-i-check-for-snapshot-dependencies-and-throw-an-exception-if-some-where-found/4064>\
**Category:** Old Forum Archive\
**Created:** [August 19, 2014, 8:02pm UTC](https://discuss.gradle.org/t/how-can-i-check-for-snapshot-dependencies-and-throw-an-exception-if-some-where-found/4064 "2014-08-19T20:02:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)\
**Post date:** [August 19, 2014, 8:02pm UTC](https://discuss.gradle.org/t/how-can-i-check-for-snapshot-dependencies-and-throw-an-exception-if-some-where-found/4064/1 "2014-08-19T20:02:00Z")

</div>

How can I check the defined dependencies of the root project and all subproject for snapshot dependencies and throw an Exception if there are dependencies on snapshot. I want to add this check in my build.gradle when building/uploading releases of my project to prevent released versions from depending on snapshots.

---

<div class="post-metadata">

**Author:** ![flow](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/flow/32/1968_2.png) [@flow](https://discuss.gradle.org/u/flow)\
**Post date:** [August 20, 2014, 5:53pm UTC](https://discuss.gradle.org/t/how-can-i-check-for-snapshot-dependencies-and-throw-an-exception-if-some-where-found/4064/2 "2014-08-20T17:53:00Z")

</div>

Here is what I came up with

```gradle
task maybeCheckForSnapshotDependencies {
 // Don't check for Snapshot dependencies if this is a snapshot.
 if (isSnapshot) return
 allprojects { project ->
  project.configurations.runtime.each {
   if (it.toString().contains("-SNAPSHOT"))
    throw new Exception("Release build contains snapshot dependencies: " + it)
  }
 }
}
  test { dependsOn maybeCheckForSnapshotDependencies }

```

I really like to avoid the String.contains() call and replace it with something like isChangingDependency(). But otherwise it seems to be working fine.
