Gradle Goodness: Add Incremental Build Support to Tasks
Gradle has a very powerful incremental build feature. This means Gradle will not execute a task unless it is necessary. We can help Gradle and configure our task so it is ready for an incremental build.
Suppose we have a task that generates a file. The file only needs to be generated if a certain property value has changed since the last task execution. Or the file needs be generated again if a source file is newer than the generated file. These conditions can be configured by us, so Gradle can use this to determine if a task is up to date or not. If the task is up to date Gradle doesn't execute the actions.
A Gradle task has an inputs and outputs property. We can assign a file(s), dir or properties as inputs to be checked. For outputs we can assign a file, dir or custom code in a closure to determine the output of the task. Gradle uses these values to determine if a task needs to be executed.
In the following sample build script we have a task generateVersionFile which create a file version.text in the project build directory. The contents of the file is the value of the version property. The file only needs to be generated if the value of version has changed since the last time the file was generated.
00.version = '1.0'01.outputFile = file("$buildDir/version.txt")02. 03.task generateVersionFile << {04.if (!outputFile.isFile()) {05.outputFile.parentFile.mkdirs()06.outputFile.createNewFile()07.}08.outputFile.write "Version: $version"09.}10. 11.generateVersionFile.inputs.property "version", version12.generateVersionFile.outputs.files outputFile13. 14.task showContents << {15.println outputFile.text16.}17.showContents.dependsOn generateVersionFileLet's run our script for the first time:
$ gradle showContents:generateVersionFile:showContentsVersion: 1.0BUILD SUCCESSFULNow we run it again and notice how Gradle tells us the task is UP-TO-DATE:
$ gradle showContents:generateVersionFile UP-TO-DATE:showContentsVersion: 1.0BUILD SUCCESSFULLet's change the build script and set the version to 1.1 and run Gradle:
$ gradle showContents:generateVersionFile:showContentsVersion: 1.1BUILD SUCCESSFULGradle Goodness: Add Incremental Build Support to Tasks的更多相关文章
- Gradle Goodness: Add Incremental Build Support to Custom Tasks with Annotations
In a previous post we learned how we can use the inputs and outputs properties to set properties or ...
- Gradle Goodness: Run a Build Script With a Different Name
Normally Gradle looks for a build script file with the name build.gradle in the current directory to ...
- Gradle Goodness: Task Output Annotations Create Directory Automatically
Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...
- Gradle Goodness: Unpacking an Archive
To create an archive with Gradle is easy. We have several tasks like Zip, Tar, Jar, War and Ear to c ...
- Gradle Goodness: Display Available Tasks
To see which tasks are available for our build we can run Gradle with the command-line option -t or ...
- Gradle Goodness: Group Similar Tasks
In Gradle we can assign a task to a group. Gradle uses the group for example in the output of $ grad ...
- Gradle Goodness: Changing Name of Default Build File
Gradle uses the name build.gradle as the default name for a build file. If we write our build code i ...
- Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects
Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. ...
- Gradle Goodness: Copy Files with Filtering
Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...
随机推荐
- POJ P2777 Count Color——线段树状态压缩
Description Chosen Problem Solving and Program design as an optional course, you are required to sol ...
- 001Spring Boot中使用MongoDB
01.下载MongoDB 点击标题链接,下载windows可用的MongoDB. 02.解压 将下载的压缩包放入C盘根目录(根据自己需要调整目录)---->解压到当前文件夹---->重命名 ...
- ant-design里为了清空Modal中的值, modal 中值有缓存 ....
处理列表中的编辑功能,发现有点爽,看的都是上次编辑后内容, 搜文档 也没说具体怎么清空旧的状态 网上搜了下,说给 moal 设置一个不同的key 试了,用这方式可以解决问题, 只要这个key是全新的 ...
- IOS CALayer的属性和使用
一.CALayer的常用属性 1.@propertyCGPoint position; 图层中心点的位置,类似与UIView的center:用来设置CALayer在父层中的位置:以父层的左上角为原点( ...
- 获取表SQLSERVER 的表结构信息(字段名,长度,精度,类型,NULL,ID,PRI)
select sys.columns.name, sys.types.name, sys.columns.precision,sys.columns.scale, sys.columns.is_nul ...
- Unity IOC/DI使用
一.IOC介绍 IOC(Inversion of Control),中文译为控制反转,又称为“依赖注入”(DI =Dependence Injection) IOC的基本概念是:不创建对象,但是描述创 ...
- 文件复制(shutil)
import shutil #拷贝整个目录树 shutil.copytree('d:\\aaa','e:\\aaa') #目标文件夹(e:\aaa)必须不存在 shutil.rmtree('e:\\a ...
- ASP.NET 控件不可编辑
前台页面的解析后的html代码为disabled="disabled",而在后台我们需要设置控件的Enabled=false:即可.
- January 01 2017 Week 1st Sunday
This is a new year. A new beginning. And things will change. 新一年,新开始,新气象. Hey Hey Hey. I can see my ...
- 51nod 1952 栈
题目链接戳这 如果只是从尾端插入,那么问题就是基础的:求取栈内最大值的问题,这用单调栈解决即可. 但是前端也能插入,一般的单调栈已经不能满足.那么想象,如果在前端插入一个小值,相当于在栈底多加一个值罢 ...