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 ...
随机推荐
- 【Codeforces】Helvetic Coding Contest 2017 online mirror比赛记
第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: l ...
- bootStrap下拉菜单 点击下拉列表某个元素,列表不隐藏
html: <a class="dropdown-toggle bgImg-priceWran " id="dropdownMenu1" data-tog ...
- 【javascript】javasrcipt设计模式之状态模式
使用场景 解决多个[ifelse]嵌套,将其封装成若干个方法 区分事物内部的状态,事物内部的状态的改变往往会带来事物的行为的改变 简单的多个状态直接切换的时候 //两个状态之间的切换,使用if-els ...
- Climbing Stairs 爬楼梯问题,每次可以走1或2步,爬上n层楼梯总方法 (变相fibonacci)
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- java多线程处理问题
今天碰到个以前的线上bug需要处理下:问题是这样的,我们的app里面有个点赞的功能,点赞完后显示点赞人列表以及点赞数量,但是数量现在总是不准确.之后查看代码,发现点赞时候只是简单的向数据库添加了一条点 ...
- Delphi IDHTTP用法详解
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入 ...
- switch与java
switch结构可以更好的解决等值判断问题switch 选择结构的语法:switch (表达式){case 常量 1://代码块1:break;case 常量 2://代码块2:break;..... ...
- EXCHANGE 2013 TLS传输层安全
默认情况下,SMTP流量是不被加密的,这就导致在公网上进行邮件沟通就像是在广播一样,任何人拦截到该邮件都可以轻而易举的读取其内容.但是现实场景中有许多敏感信息是通过邮件来进行发送的,所以其中一种保护邮 ...
- MySQL 数据库--权限管理
权限管理 1.创建账号 创建本地账号 create user 'luke'@'localhost' identified by '123'; #mysql -uluke -p123 创建远程账号 cr ...
- 乘风破浪:LeetCode真题_004_Median of Two Sorted Arrays
乘风破浪:LeetCode真题_004_Median of Two Sorted Arrays 一.前言 说到算法,最难的就是一些需要通过分析得到一些递推公式或者有用的结论,进而用来解决问题的方法了. ...