所以我创建了一个档案,说一场战争,然后我想要另一个带有不同名称的副本以方便起见。事实是,我不希望复制任务减慢这个相当大的构建的其余部分。可以异步执行吗?如果是这样,怎么样?
答案 0 :(得分:1)
在某些情况下,使用parallel execution feature非常方便。它仅适用于多项目构建(您要并行执行的任务必须位于不同的项目中)。
project('first') {
task copyHugeFile(type: Copy) {
from "path/to/huge/file"
destinationDir buildDir
doLast {
println 'The file is copied'
}
}
}
project('second') {
task printMessage1 << {
println 'Message1'
}
task printMessage2 << {
println 'Message2'
}
}
task runAll {
dependsOn ':first:copyHugeFile'
dependsOn ':second:printMessage1'
dependsOn ':second:printMessage2'
}
默认输出:
$ gradle runAll
:first:copyHugeFile
The file is copied
:second:printMessage1
Message1
:second:printMessage2
Message2
:runAll
--parallel
的输出:
$ gradle runAll --parallel
Parallel execution is an incubating feature.
:first:copyHugeFile
:second:printMessage1
Message1
:second:printMessage2
Message2
The file is copied
:runAll
答案 1 :(得分:1)
import java.util.concurrent.*
...
def es = Executors.newSingleThreadExecutor()
...
war {
...
doLast{
es.submit({
copy {
from destinationDir.absolutePath + File.separator + "$archiveName"
into destinationDir
rename "${archiveName}", "${baseName}.${extension}"
}
} as Callable)
}
}