当前位置:网站首页>How to solve the task cache compilation problem caused by gradle build cache
How to solve the task cache compilation problem caused by gradle build cache
2022-06-23 13:23:00 【Yisu cloud】
Gradle Build Cache It caused Task How to solve the cache compilation problem
Today I'd like to share with you Gradle Build Cache It caused Task How to solve the cache compilation problem , Detailed content , Clear logic , I believe most people still know too much about this knowledge , So share this article for your reference , I hope you will gain something after reading this article , Now let's take a look .
Basic knowledge of
Gradle Building a cache is a caching mechanism , Designed to save time by reusing output from other builds . Build cache by storing ( Local or remote ) Build the output and allow the build to get the output from the cache when it determines that the input has not changed , Thus avoiding the expensive work of regenerating them .
The first function of using build cache is task output cache . Essentially , The task output cache utilizes the same intelligence as the latest check , When a previous local build has produced a set of task outputs ,Gradle Use it to avoid work . however , The task output cache is not limited to previous builds in the same workspace , But to allow Gradle Reuse any early built task output anywhere on the local machine . When using shared build cache for task output caching , This can even work across developer machines and build agents .
In addition to the task , Artifact transformation can also take advantage of the build cache and reuse its output , Similar to task output cache .
Excerpt from above gradle Official documents , Links are as follows
I'll simply translate it to you guys , Exist locally build cache Under the circumstances ,gradle task Will be cached based on the current input key value , If the input has not changed , It means Ben Task Can be skipped , In addition, this is different from incremental compilation .

You can steal official pictures again . Take a chestnut ,JavaCompiler task Of input java The file is the same as the one compiled last time , This means that the task can use the original compilation output as the compilation product .
Cacheable tasks
Task type needs to be used @CacheableTask Note: select to add the task output cache . Please note that ,@CacheableTask Not inherited by subclasses . By default , Custom task types cannot be cached .
There are official instructions on how to use compilation cache , First of all, our Task To be defined as @CacheableTask.
In addition to Task Internal input and output also need to be marked @TaskInputs and @TaskOutputs annotation . Only in this way can we ensure the current Task With the ability of compiling and caching .
So you want to have the ability to write a cache Task It's also complicated . That's why Android It will start to push Artifacts Used , Let developers care less about the logic related to input and output .
We have upgraded the adapter AGP 7.0 | gossip
So relative , No definition @CacheableTask , it is considered to be a task with a compilation cache .
TaskOutput
In the above skipped tasks , Usually there will be in Task After compiling, bring some special identifiers .
(no label) or EXECUTEDThe task was carried out normally .UP-TO-DATEThe task output has not changed .The input and output have not changed .
The task was carried out , But the mission tells gradle The output has not changed .
The task is not executed and some dependencies , But all dependencies are up to date 、 Skipped or from cache .
The task is not performed or relied on .
FROM-CACHEThe output of the task can be found in the previous execution . Task has recovered output from build cache .SKIPPEDThe task was not performed . The task has been explicitly excluded from the command line .NO-SOURCEThis task is not currently required . Input content has no source file , such as.java
In a nutshell , Except for the first case , The rest is that the task is skipped .
Interesting compilation problems
Okay , With the pre knowledge reserve , Let's talk about a strange problem we have encountered recently .
We have a protobuf Compiled warehouse , Be in charge of pb File to java perhaps kotlin. Then the generated files will be moved to the other two modules for packaging , Finally, delete all generated class files . Then go ahead and do it javacompiler task.
There is a secondary compilation problem in this module . Packing for the first time protobuf Module compilation is normal , Then when the module is compiled twice , The module will have the problem of class loss .
Problem analysis
This problem is relatively simple to analyze . In the case of secondary compilation , Because the input has not changed , So it triggers Gradle Task Related cache , And then all of the pb File to java kt The process is skipped . But the follow-up copy task Because it doesn't have caching capacity , So he'll do it again cv The task of . But the original generation java and kt It has been deleted . At this time, he will overwrite the empty folder . Then it leads to the original java and kt The problem of losing all the files .
This is a very interesting build cache Resulting in strange problems , Because the last task has a compilation cache , After that, I skipped the compilation and directly used the original output Output . But the next task is not cached , Therefore, the copy task must still be performed .
That's all “Gradle Build Cache It caused Task How to solve the cache compilation problem ” All the content of this article , Thank you for reading ! I believe you will gain a lot after reading this article , Xiaobian will update different knowledge for you every day , If you want to learn more , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- 1 channel 100m optical fiber transceiver 1 100m optical 1 100m electric desktop Ethernet optical fiber transceiver built-in power supply
- A bug development means that the user will not operate like this, and there is no need to repair it. How should testers respond?
- 快速了解常用的非对称加密算法,再也不用担心面试官的刨根问底
- AAIG看全球6月刊(上)发布|AI人格真的觉醒了吗?NLP哪个细分方向最具社会价值?Get新观点新启发~
- R language uses matchit package for propensity matching analysis (set the matching method as nearest, match the control group and case group with the closest propensity score, 1:1 ratio), and use matc
- 怎么手写vite插件
- Androd Gradle模块依赖替换如何使用
- [website architecture] the unique skill of 10-year database design, practical design steps and specifications
- Configure SSH Remote Login for H3C switch
- 理财产品长期是几年?新手最好买长期还是短期?
猜你喜欢

What are the criteria for judging the end of the test?

Analyse et résolution des défaillances de connexion causées par MySQL utilisant replicationconnection

#yyds干货盘点# 解决剑指offer: 判断是不是平衡二叉树

Hanyuan high tech USB3.0 optical transceiver USB industrial touch screen optical transceiver USB3.0 optical fiber extender USB3.0 optical fiber transmitter

Part C - value types and reference types

New project, how to ensure the coverage of the test?

90%的人都不懂的泛型,泛型的缺陷和应用场景

Germancreditdata of dataset: a detailed introduction to the introduction, download and use of germancreditdata dataset

What should testers do if the requirements need to be changed when the project is half tested?

First exposure! The only Alibaba cloud native security panorama behind the highest level in the whole domain
随机推荐
The filter function of dplyr package in R language filters the data rows containing the specified string in the specified data column of dataframe data based on the grepl function
Go write permissions to file writefile (FileName, data, 0644)?
Androd Gradle模块依赖替换如何使用
Homekit supports the matter protocol. What does this imply?
When did the redo log under InnoDB in mysql start to perform check point disk dropping?
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses the summary function to obtain the summary statistical information of the
R语言使用构建有序多分类逻辑回归模型、ordinal.or.display函数获取有序逻辑回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)、汇总统计结果保存到csv
What should I do if a serious bug occurs within the scope of my own test and I am about to go online?
4E1 PDH optical transceiver 19 inch rack type single fiber transmission 20km E1 interface optical network optical transceiver
Dataset之GermanCreditData:GermanCreditData数据集的简介、下载、使用方法之详细攻略
Wallys/DR6018-S/ 802.11AX MU-MIMO OFDMA / 2* GE PORTS/WIFI 6e / BAND DUAL CONCURRENT
支持HomeKit、NFC:智汀智能门锁SL1仅需要149元
Interview question: for example, how do you do interface testing at work?
Architecture design methods in technical practice
Have you ever encountered incompatibility between flink1.15.0 and Flink CDC MySQL 2.2.1? f
同花顺网上开户安全吗,需要注意什么
CDH mail alarm configuration
Hanyuan hi tech 8-way telephone +1-way 100M Ethernet RJ11 telephone optical transceiver 8-way PCM telephone optical transceiver
深入思考:《盖亚奥特曼》中部分情景深度分析及反射出的哲理与感悟
sed -i命令怎么使用