【问题标题】:Gradle Task DependenciesGradle 任务依赖
【发布时间】:2018-03-28 18:36:05
【问题描述】:

我怎么能在 gradle 中做到这一点:例如。想在任务中使用HTTPBuilder

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??
}

【问题讨论】:

    标签: dependencies task gradle


    【解决方案1】:

    要直接在构建脚本中使用类,您需要在 buildscript { } 闭包中将依赖项声明为脚本类路径的一部分。例如:

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

    【讨论】:

    • 是的 - 谢谢!过了一会儿,终于在文档中找到了。我还将我的数据库驱动程序放在同一个 buildscript 闭包中,但是类加载器似乎找不到它们?还有什么技巧可以用吗?
    • 啊刚刚在这里找到你的帖子亚当,再次感谢我猜 ;) mail-archive.com/user@gradle.codehaus.org/msg02450.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 2017-10-29
    • 2014-03-30
    相关资源
    最近更新 更多