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 files that need to be checked to see if a task is up to date. In this post we learn how a custom task class can use annotations to set input properties, file or files and output files or dir.
For input we can use @Input, @InputFile, @InputFiles or @InputDirectory annotations. Gradle uses the properties with annotations for checking if a task is up to date. Output file or directory can be marked with @OutputFile and @OutputDirectory.
00.task generateVersionFile(type: Generate) {01.version = '2.0'02.outputFile = file("$project.buildDir/version.txt")03.}04. 05.task showContents << {06.println generateVersionFile.outputFile.text07.}08.showContents.dependsOn generateVersionFile09. 10.class Generate extends DefaultTask {11.@Input12.String version13. 14.@OutputFile15.File outputFile16. 17.@TaskAction18.void generate() {19.def file = getOutputFile()20.if (!file.isFile()) {21.file.parentFile.mkdirs()22.file.createNewFile()23.}24.file.write "Version: ${getVersion()}"25.}26.}We can run our task and get the following output:
$ gradle showContents:generateVersionFile:showContentsVersion: 2.0BUILD SUCCESSFULAnd if we run it again we see the task is now up to date:
$ gradle showContents:generateVersionFile UP-TO-DATE:showContentsVersion: 2.0BUILD SUCCESSFULWe can change the version numer in our build script to 2.1 and see the output:
$ gradle showContents:generateVersionFile:showContentsVersion: 2.1BUILD SUCCESSFULGradle Goodness: Add Incremental Build Support to Custom Tasks with Annotations的更多相关文章
- Gradle Goodness: Add Incremental Build Support to Tasks
Gradle has a very powerful incremental build feature. This means Gradle will not execute a task unle ...
- 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: Continue Build Even with Failed Tasks
If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have f ...
- 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: Adding Tasks to a Predefined Group
In Gradle we can group related tasks using the group property of a task. We provide the name of our ...
- 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 ...
随机推荐
- <Android 应用 之路> MPAndroidChart~BubbleChart(气泡图) and RadarChart(雷达图)
简介 MPAndroidChart是PhilJay大神给Android开发者带来的福利.MPAndroidChart是一个功能强大并且使用灵活的图表开源库,支持Android和iOS两种,这里我们暂时 ...
- Python3 中日语料分句实现
0. 背景 因为最近在看平行语料句对齐.词对齐的缘故,想做对齐的话需要先做一个分句. 一开始利用正则和引号开关标志写了一种方法,中间想到一个小技巧,写出来比较简单通用,想把这一小段代码分享一下. 1. ...
- 同步(Synchronous)和异步(Asynchronous)的概念
web项目中的同步与异步 在我们平时的web项目开发中会经常听到ajax请求这样一个称呼,在web项目中可以通过js或者jquery发送同步请求又或者异步请求,同步请求呢往往代表着你必须等待这次请求结 ...
- Newtonsoft.Json 动态解析 json字符串
有一个json字符串是动态的,如下面,columns中的数量是不固定的,因此就不能使用反序列化类的方法了: 因此使用这样一种方式,把columns中的所有东西都输出出来: public void Ge ...
- 何时需要做urlEncode,以及为什么要做
在RFC1738中,对于URL可以使用的字符集做了如下规定: “ 只有0-9a-zA-Z的字母以及$-_.+!*'(),"这几个特殊字符 ” 而在html4中扩展了所有的unicode ch ...
- php 3des加密 兼容JAVA 多么痛的领悟呀
最近和别人做接口用到SOCKET TCP/IP方式 其中需要对账号和密码进行3DES加密 对方提供了一个加密比对的软件和JAVA的实现代码 并且给了我们一个长度为32位的密钥 这边需要用PHP来实现! ...
- course & time
- Java学习---TCP Socket的学习
基础知识 1. TCP协议 TCP是一种面向连接的.可靠的.基于字节流的运输层(Transport layer)通信协议.在简化的计算机网络OSI模型中,它完成第四层传输层所指定的功能,UDP是同一层 ...
- 乘风破浪:LeetCode真题_005_Longest Palindromic Substring
乘风破浪:LeetCode真题_005_Longest Palindromic Substring 一.前言 前面我们已经提到过了一些解题方法,比如递推,逻辑推理,递归等等,其实这些都可以用到动态规划 ...
- linux setup 相关text mode图形配置工具的安装
centos 6.4 x86_64 minimal安装后发现setup命令不可用 yum update yum install setup 安装完了还是不可用,不知为什么,难道装的那个包不对?yum ...