我希望能够写出这样的内容:
dependencies {
myConfig computeMyDependency()
}
我希望能够说"没有依赖"。返回null或空映射不起作用。我想我可以返回files('/dev/null')
,但这很奇怪,黑客且不便携。我可以使用某种类型的null依赖构造函数吗?
一些背景知识:
我真正想做的是将依赖下载推迟到实际执行时间。看起来如果写一个任务,例如像这样的复制任务:
task copyMyDependencyFile(type: Copy) {
from { configurations.myConfig
.grep { it.name.endsWith("zip") }
.collect() { zipTree it }
}
into targetDir
}
然后运行./gradlew tasks
实际上会执行from
关闭,这让我很难过。 (使用Gradle 2.4)
答案 0 :(得分:0)
快速解决方法也可能是:
task copyMyDependencyFile << {
copy {
from {
configurations.
compile.
grep { it.name.endsWith("jar") }.
collect { zipTree it }
}
into targetDir
}
}
它应该是便携式的。
不确定但from
和into
可能在doLast
关闭Copy
类型的任务时配置:
task copyMyDependencyFile(type: Copy) {
doLast {
from {
configurations.
compile.
grep { it.name.endsWith("jar") }.
collect { zipTree it }
}
into targetDir
}
}
请亲自尝试后者。