Gradle build cache is not enabled for task

dharanikesav picture dharanikesav · May 24, 2018 · Viewed 9.6k times · Source

I have enabled gradle build cache for my project. But, we are using some non-built in tasks like npm-install from third party plugins. Gradle is not enabling cache for these tasks. For example it shows something like below when such task is executed :

Task :data-export-ui-kjs:npm-configure
Build cache key for task ':data-export-ui-kjs:npm-configure' is bbe0dafcd467a2afb2834acafe2993f5
Caching disabled for task ':data-export-ui-kjs:npm-configure': Caching has not been enabled for the task

Is there a way to enable build cache for such non-builtin tasks?

Answer

wolfs42 picture wolfs42 · May 28, 2018

A task needs to opt-in to being cacheable (see Cacheable tasks), since it doesn't make sense for every task to be cacheable.

Opting in can happen by annotating the task with @CacheableTask or by using task.outputs.cacheIf { true }, so you could do that for the npm configure task.

Note that cacheable tasks need to declare their inputs and outputs correctly. If they don't, then you may experience invalid build failures.