2010-09-20 225 views
3

我怎样才能在gradle中做到这一点:例如,想在任务中使用HTTPBuilder。Gradle任务依赖关系

的build.gradle:

repositories { 
mavenRepo urls: "http://repository.codehaus.org" 
} 
configurations { 
testConfig 
} 
dependencies { 
testConfig 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.0' 
} 

task someTaskThatUsesHTTPBuilder (dependsOn: configurations.testConfig) << { 
    new HTTPBuilder()// <--this cannot be resolved/found?? 
} 

回答

4

直接在你的构建脚本中使用一个类时,你需要声明依赖作为buildscript {}关闭脚本的类路径的一部分。例如:

buildscript { 
    repositories { 
     mavenRepo urls: "http://repository.codehaus.org" 
    } 
    dependencies { 
     classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.0' 
    } 
} 
+1

是的 - 谢谢!最后在文档中发现一段时间后。我也把我的数据库驱动程序放在相同的构建脚本中,但类加载器似乎无法找到它们?还有另一个窍门可以使用吗? – jhall 2010-09-21 12:58:32

+1

刚刚在这里找到你的帖子亚当,再次感谢我;)http://www.mail-archive.com/[email protected]/msg02450.html – jhall 2010-09-21 13:11:45