A cacheable task stores the output files of a task in order to avoid future processing work. Since your example task has no output files it makes no sense to make it a cacheable task (there’s nothing to cache from a delete operation).
Perhaps one of your other tasks is a better example to work from?
Yeah, come to think of it a delete task should never be cacheable. Typically a delete task is used to clean rather than build.
Is this delete task part of your build? Or just part of your clean?
If you’re deleting as part of your build, perhaps you could change the logic so that it’s not required. I’d need to understand your build better. Perhaps you could instead copy zips from torBinariesDir to another location and use that instead. Or if you previously unzipped to torBinariesDir you could limit your unzipping to *.zip
In a perfect world you could run your build twice in a row and the second run would do nothing since everything’s cached. With a Delete task in your build this will never be true
task unpackTorBinaries {
doLast {
copy {
from configurations.tor.collect { zipTree(it) }
into torBinariesDir
// TODO: Remove after next Tor upgrade, which won't include non-PIE binaries
include 'geoip.zip', '*_pie.zip'
}
}
dependsOn cleanTorBinaries
}
You could could change to this which is cacheable
task unpackTorBinaries(type: Copy) {
from configurations.tor.collect { zipTree(it) }
into torBinariesDir
include 'geoip.zip', '*_pie.zip'
doFirst {
delete torBinariesDir
}
}
Or perhaps if unzipping is expensive and you want to delay until execution phase
task unpackTorBinaries {
inputs.files configurations.tor
outputs.dir torBinariesDir
doLast {
delete torBinariesDir
copy {
from configurations.tor.collect { zipTree(it) }
into torBinariesDir
include 'geoip.zip', '*_pie.zip'
}
}
}