当前位置:网站首页>Task cache compilation caused by gradle build cache
Task cache compilation caused by gradle build cache
2022-06-22 22:19:00 【1024 Q】
Preface
Basic knowledge of
Cacheable tasks
TaskOutput
Interesting compilation problems
Problem analysis
Last
PrefaceA while ago, an article was published in the subsidiary. If you are interested, you can have a look , Introduce the principle of compilation optimization , Of course, there are some technical details that have not been written .
Bili, Bili Android Compile optimization .
Basic knowledge ofGradle 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 .
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 .
In the above skipped tasks , Usually there will be in Task After compiling, bring some special identifiers .
(no label) or EXECUTED The task was carried out normally .
UP-TO-DATE The 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-CACHE The output of the task can be found in the previous execution . Task has recovered output from build cache .
SKIPPED The task was not performed . The task has been explicitly excluded from the command line .
NO-SOURCE This 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 problemsOkay , 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 .
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 .
As for the solution, I won't write , I don't think everyone should be interested .
LastSay the important thing again , A while ago, I rolled up an article in the company. If you are interested, you can have a look , Introduce the principle of compilation optimization , Of course, there are some technical details that have not been written .
https://www.jb51.net/article/252481.htm
That's all Gradle Build Cache It caused Task Details of cache compilation problems , More about Gradle Build Cache compile Task For cached information, please pay attention to other relevant articles on the software development network !
边栏推荐
- Why do you think it is common for Chinese people to earn more than 10000 yuan a month?
- [GWCTF 2019]mypassword XSS
- 6-5 图的深度遍历-邻接矩阵实现
- CSV add a new column
- 自监督表征预训练之掩码图像建模:CAE 及其与 MAE、BEiT 的联系
- 2022年朝阳区科技创新课之“产品创新与成果转化”训练营活动圆满结束
- Système de bibliothèque libre - service - cas de conception complète de l'interface tkinter et du formulaire openpyxl
- 微软 Edge 浏览器将支持网络测速,内置计算器和单位转换工具
- shell(34) : 时间
- Cannot re register id: pommeffacompetition-v0 problem solving
猜你喜欢

In 2022, the "product innovation and achievement transformation" training camp of Chaoyang District Science and technology innovation class was successfully completed

自助图书馆系统-Tkinter界面和openpyxl表格综合设计案例

Rapideye, spot satellite remote sensing image data

校园跑腿管理端APP—陕西格创

Research hotspot - Official publicity! The release time of JCR zoning and impact factors will be determined in 2022!

Adblock blocks Baidu hot search

注意|24日截止 2022年广东二级造价工程师准考证打印入口开通
![[ROS introduction] cmakelist Txt and packages XML interpretation](/img/37/24ce4be244ea56c2c84342492fccd4.png)
[ROS introduction] cmakelist Txt and packages XML interpretation

For an unforgettable memory: special topic of Sun Jian

考生必读篇 | PMP6月25日考试临近,需要注意什么?
随机推荐
Makefile:1860: recipe for target ‘cmake_ check_ build_ system‘ failed make: *** [cmake_check_build_syst
Lesson 026: Dictionary: when the index is not easy to use 2 | after class test questions and answers
The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?
Cvpr2022 𞓜 Heidelberg University's course "deep visual similarity and measurement learning"
British teddy bear joins the pubg mobile game
[geometric vision] 4.2 piecewise linear transformation
Implementation of breadth traversal adjacency matrix of 6-6 graph
Eureka服务注册与发现
What is a data asset? How should data asset management be implemented?
立体渲染
[GWCTF 2019]mypassword XSS
勒索病毒横行下设备该如何进行加密防护
7-1 creating a binary tree from a preorder sequence
Ten thousand words long text | use RBAC to restrict access to kubernetes resources
Kdd'22 | Ali: fine tuning CTR estimation based on EE exploration
7-1 前序序列创建二叉树
Vs code one key sorting shortcut
LeetCode 每日一题——513. 找树左下角的值
≥ server2012r2 system, disable some planned tasks of the system
Solve the problem that MySQL in phpstudy cannot be started and conflicts with locally installed MySQL