groovy - gradle在复制中合并configurations.testRuntime和configurations.testCompile

标签 groovy gradle

我想将我的一些依赖项(从maven中检索)复制到build.gradle文件中的特定位置。

如果我仅迭代testRuntime,则工作正常。我的代码是:

dependencies {
  testRuntime 'p6spy:p6spy:2.+'
  testRuntime 'com.h2database:h2:1+'
}

task foo {
    copy {
        from configurations.testRuntime.findAll { it.getAbsolutePath().contains("/p6spy/") || it.getAbsolutePath().contains("/h2/") }
        into "outputdir"
    }
}

但是我想使用testCompile而不是testRuntime,以防h2依赖。所以我尝试了:
dependencies {
  testRuntime 'p6spy:p6spy:2.+'
  testCompile 'com.h2database:h2:1+'
}

task foo {
    copy {
        from [ configurations.testRuntime, configurations.testCompile ].flatten().findAll { it.getAbsolutePath().contains("/p6spy/") || it.getAbsolutePath().contains("/h2/") }
        into "outputdir"
    }
}

但是在这里我得到错误:
No such property: from for class: org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated

我想麻烦是我在这里合并两个列表。仍然找不到正确的方法。

最佳答案

您的解决方案将在每次构建调用时复制文件,即使未调用foo任务也是如此。这是一个正确的解决方案:

task foo(type: Copy) {
    from configurations.testRuntime // includes configurations.testCompile  
    into "outputdir"
    include "**/p6spy/**" 
    include "**/h2/**"  
}

关于groovy - gradle在复制中合并configurations.testRuntime和configurations.testCompile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23007020/

相关文章:

grails - 按日期获取所有记录,而忽略Grails中DateTime中的时间

jenkins - Groovy 脚本取消在 Email-Ext 插件中发送电子邮件

java - renameTo() 不起作用

gradle - 从闭包访问局部变量

java - 任务 ':compileGroovy'的执行失败。 org.springframework.security.authentication.encoding.PasswordEncoder

java - Groovy 应用程序中 RxJava fromCallable() 方法的 IntelliJ 编译错误?

intellij-idea - Gradle 插件在 Intellij IDEA(计算任务图)中不起作用?

升级到 Java 8 和构建工具版本 25 后 Android 测试用例失败

android - "env: bash: No such file or directory"尝试在 Mac Mini 上的 Jenkins 上运行 gradle

android - 创建预构建事件以将文件复制到 Android 应用程序中的 Assets 文件夹