Created
March 30, 2014 09:51
-
-
Save darylteo/9870381 to your computer and use it in GitHub Desktop.
Detecting if a dependency is valid in Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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