Gradle Goodness: Automatic Clean Tasks
Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This task is able to remove any output files or directories we have defined for our task. For example we can assign an output file or directory to our task with the outputs property. Or we can use the @OutputFile and @OutputDirectories annotations for custom task classes. The clean<Taskname> rule can delete the output files or directories for the task with the name <Taskname> for us. We don't have to write the clean task ourselves we only have define the base plugin in our project. And Gradle will take care of the rest!.
00.apply plugin: 'base'01. 02.outputDir = file("$buildDir/generated-src")03.outputFile = file("$buildDir/output.txt")04. 05.task generate << {06.outputDir.mkdirs()07.outputFile.write 'Generated by Gradle.'08.}09.generate.outputs.files outputFile10.generate.outputs.dir outputDir11. 12.task showBuildDir << {13.def files = buildDir.listFiles()14.files.each {15.print it.directory ? 'Dir: ' : 'File: '16.println it.name17.}18.println "${files.size()} files in $buildDir.name"19.}We can first run the generate task and see the output file and directory.
$ gradle -q generate showBuildDirDir: generated-srcFile: output.txt2 files in buildNext we can run the task cleanGenerate, which is added to the project by Gradle, and see the output files are gone.
$ gradle -q cleanGenerate showBuildDir0 files in buildGradle Goodness: Automatic Clean Tasks的更多相关文章
- 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: 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: Task Output Annotations Create Directory Automatically
Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...
- 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 ...
- 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: Excluding Tasks for Execution
In Gradle we can create dependencies between tasks. But we can also exclude certain tasks from those ...
随机推荐
- MYSQL-EXPLAIN 命令详解 (转载)
EXPLAIN 命令详解 在工作中,我们用于捕捉性能问题最常用的就是打开慢查询,定位执行效率差的SQL,那么当我们定位到一个SQL以后还不算完事,我们还需要知道该SQL的执行计划,比如是全表扫描, ...
- UOJ#55. 【WC2014】紫荆花之恋
传送门 暴力思路就是每次点分治计算答案 点分治之后,条件可以变成 \(dis_i-r_i\le r_j-dis_j\) 每次只要查找 \(r_j-dis_j\) 的排名然后插入 \(dis_j-r_j ...
- Ubuntu16.04 下安装tomcat
有两种常用方法: 一.通过 apt-get 命令进行在线安装(会自动配置好环境变量和服务) 二.通过下载并解压 .tar.gz 包进行手动安装(需要手动配置环境变量) 一.通过 apt-get 命令进 ...
- Bootstrap框架和inconfont、font-awesome使用
iconfont的使用:https://www.cnblogs.com/clschao/articles/10387580.html Bootstrap介绍 Bootstrap是Twitter开源的基 ...
- Python 关于bytes类方法对数字转换的误区, Json的重要性
本文起源于一次犯错, 在发觉bytes()里面可以填数字, 转出来的也是bytes类型, 就心急把里面的东西decode出来. 结果为空.搞来搞去以为是命令不熟练事实上错在逻辑. a1 = bytes ...
- JavaScript-原型&原型链&原型继承&组合函数
小小的芝麻之旅: 今天学习了js的原型,要说原型,我们先简单说一下函数创建过程. 原型 每个函数在创建的时候js都自动添加了prototype属性,这就是函数的原型,原型就是函数的一个属性,类似一个指 ...
- Java学习笔记(4)----Public,Protected,Package,Private修饰符可见性
Java修饰符类型(public,protected,private,friendly) public的类.类属变量及方法,包内及包外的任何类均可以访问:protected的类.类属变量及方法,包内的 ...
- Linked List Cycle 判断一个链表是否存在回路(循环)
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...
- angular based app开发流程
整理user story mock UI,生成满足上述user story的原型界面 根据上述UI,整理出data model(适用于后端和angular的数据模型) 后端CRUD开发,形成REST ...
- 【Oracle】Update方法
1.单表更新 update customers set city_name='山西省太原市' where city_name='山西太原' 2.两表(多表)关联update -- 被修改值由另一个表运 ...