我想将我的一些依赖项(从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/