Reputation: 5489
So I create an archive, say a war, and then I want another copy with a different name for convenience. Thing is that I don't want that copy task to slow down the rest of this rather large build. Possible to execute it asynchronously? If so, how?
Upvotes: 6
Views: 2852
Reputation: 5489
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)
}
}
Upvotes: 3
Reputation: 1844
In some cases, it's very handy to use parallel execution feature for this. It works only with multiproject builds (the tasks you want to execute parallel must be in separate projects).
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'
}
The default output:
$ gradle runAll
:first:copyHugeFile
The file is copied
:second:printMessage1
Message1
:second:printMessage2
Message2
:runAll
The output with --parallel
:
$ gradle runAll --parallel
Parallel execution is an incubating feature.
:first:copyHugeFile
:second:printMessage1
Message1
:second:printMessage2
Message2
The file is copied
:runAll
Upvotes: 4