Gradle build cache is not enabled for task
Asked Answered
B

2

12

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?

Belemnite answered 24/5, 2018 at 12:9 Comment(0)
B
11

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.

Binetta answered 28/5, 2018 at 7:21 Comment(2)
So, how to enable cache for a task?Mcnamara
My answer already contains (@CacheableTask or task.outputs.cacheIf { true }). For more documentation see the Gradle user guide section.Binetta
R
1

Gradle documentation says:

There are third party plugins that work well with the build cache. The most prominent examples are the Android plugin 3.1+ and the Kotlin plugin 1.2.21+. For other third party plugins, check their documentation to find out whether they support the build cache.

So it depends on the plugin which provides the task npm-configure.

If you are using the gradle-node-plugin from SRS, it should work since version 1.2.0 according to their changelog.

Resurrectionist answered 24/5, 2018 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.