How to make copy task cacheable?


(Nitish Kumar) #1

Suppose I need to make a copy task cacheable. How can i achieve this? It is not about just copy task, it’s just how can i achieve this?
task(‘sample’, type: Copy) {
from 'a’
into ‘b’
}

Above task, if I have to run second time with gradlew clean sample , it should take from-cache.


(Stefan Wolf) #2

Hi Nitish,

there are two ways for a task to opt-in to task output caching: attaching @CacheableTask to the task class or by using the runtime API method cacheIf { true }, e.g.

sample.outputs.cacheIf { true }

Note that a cacheable task should be well behaved and should clean up leftover outputs from the last run.

Cheers,
Stefan