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 ...
随机推荐
- PHP开发支付宝之电脑网站支付--流程简介
前言 前端时间自己开发了一个drupal的支付宝模块,现在整理一下过程,因为支付宝官方网站提供的接口及文档都是新接口的,而且使用新接口的过程比较麻烦一点,所以整理一下 1.支付宝的账号必须经过企业资格 ...
- log4net.dll添加报错
描述: 新建项目Log4Net类库项目,添加log4net.dll,封装Log类对日志进行操作 新建webForm项目添加Log4Net类库生成的dll生成日志,页面报错,未能加载文件或程序集log4 ...
- Install dotNet Core on Mac
1. 按照官方页面进行安装 https://www.microsoft.com/net/core#macos 2. 在运行"brew link --force openssl" 时 ...
- 系统测试用例评审checklist
规则要素内容 使用范围 审查结果 “否”的理由 “免”的理由 规则 建议 是 否 免 规范性规则 用例是否按照公司规定的模板进行编写? √ 用例的 ...
- IntelliJ Idea编译报错:javacTask: 源发行版 1.8 需要目标发行版 1.8
解决办法: 1.Project Settings-Modules,选择项目,选择language level 8 2.选中项目,右击选择Maven-->Reimport, 再次编译. 3.Fil ...
- 一次线上bug引起的反思
今天线上又出现了一个bug,而且代码是我写的.之前这个问题也出现过,不过由于每次情况都不同,改来改去总是改不完.之后领导知道后也很恼火,让测试把每种情况都测试了下,而我也又一次重新检查了下代码.当时确 ...
- Android设备网络压力测试
网络测试的几个维度: 网络的性能 带宽:通过TCP测试来量度 时延:用ping命令量度 数据报丢失:用Iperf UDP测试来量度 Jitter(延时变化):用Iperf UDP测试来量度 信号强度( ...
- Django Ajax的使用
简介: AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 不是新的编程语言,而是一种使用现有标准的新方法. AJAX ...
- 【转】网络管理员必知之:IP地址划分
1.IP地址分类 IP地址有四个段,包括网络标识和主机标识两部分:netid+hostid. IP地址应用分为A.B.C三类,D.E类是保留和专用的. ...
- 字典构造、合并(dict)、排序
使用dict,zip方法将两个list合并为dict keys = ["b", "a", "c", "e", " ...