未为任务启用Gradle构建缓存 [英] Gradle build cache is not enabled for task

查看:601
本文介绍了未为任务启用Gradle构建缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的项目启用了gradle构建缓存.但是,我们正在使用一些非内置的任务,例如来自第三方插件的npm-install. Gradle没有为这些任务启用缓存.例如,执行此类任务时,它显示如下所示:

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?

推荐答案

任务需要选择可缓存(请参阅

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

通过使用 @CacheableTask 或使用task.outputs.cacheIf { true },因此您可以对npm configure任务执行此操作.

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.

这篇关于未为任务启用Gradle构建缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆