Skip to content

Instantly share code, notes, and snippets.

@darylteo
Created March 30, 2014 09:51
Show Gist options
  • Select an option

  • Save darylteo/9870381 to your computer and use it in GitHub Desktop.

Select an option

Save darylteo/9870381 to your computer and use it in GitHub Desktop.
Detecting if a dependency is valid in Gradle
def doesModuleExist(def notation) {
try {
def dep = project.dependencies.create(notation)
def conf = project.configurations.detachedConfiguration(dep)
// force resolution
def files = conf.files
} catch (Exception e) {
e.printStackTrace()
return false
}
return true
}
repositories {
mavenCentral()
}
task testDeps() << {
println doesModuleExist('invalid~notation~1.0.0')
println doesModuleExist('com.darylteo.vertx:vertx-gradle-plugin:0.1.0') // exists - returns true
println doesModuleExist('com.darylteo.vertx:vertx-gradle-plugin:0.1.1') // does not exist - returns false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment