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 outputFile
10.
generate.outputs.dir outputDir
11.
12.
task showBuildDir << {
13.
def
files = buildDir.listFiles()
14.
files.
each
{
15.
print
it.directory ?
'Dir: '
:
'File: '
16.
println
it.name
17.
}
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 showBuildDir
Dir: generated-src
File: output.txt
2 files in build
Next we can run the task cleanGenerate, which is added to the project by Gradle, and see the output files are gone.
$ gradle -q cleanGenerate showBuildDir
0 files in build
Gradle 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 ...
随机推荐
- 原生canvas写的飞机游戏
一个原生canvas写的飞机游戏,实用性不大,主要用于熟悉canvas的一些熟悉用法. 项目地址:https://github.com/BothEyes1993/canvas_game
- bootstrap fileinput +springmvc图片上传-krajee
引入的文件 <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/css/filei ...
- 再谈javascript函数节流
之前写过但是不记得在哪了,今天同事要一个滑到页面底部加载更多内容的效果,又想起了这玩意儿,确实挺实用和常用的,谨此记之. 函数节流从字面上的意思就是节约函数的执行次数,其实现的主要思想是通过定时器阻断 ...
- sdoi 2017 r1游记
第一次参加省选... 不过幸亏我参加过WC和THUWC,还是有些经验的. 经验就是:多拿部分分(不过话说我的部分分大部分都丢了). D1: 第一题没有预处理斐波那契数列的幂,算复杂度算错了...丢了4 ...
- codechef Many Lists(树状数组 set)
题意 题目链接 Sol 直接做肯定不好搞(反正我不会..) 直接开\(n\)个Pair类型的set,维护每个数的出现位置 每次在set中二分后暴力合并即可 然后就是树状数组的基本操作了 时间复杂度:\ ...
- git 之奇技淫巧
1,git remote prune origin 本地有很多其实早就被删除的远程分支,可以用 git remote prune origin 全部清除掉,这样再 checkout 别的分支时就清晰 ...
- spring 与springmvc容器的关系
spring容器是springmvc的父容器,而父容器是不能访问子容器中的东西,但子容器可以访问父容器的东西
- Android 图文混排 通过webview实现并实现点击图片
在一个开源项目看到是用的webview 实现的 1. 这是在asset中的一个模板html <html> <head> <title>News Detail< ...
- jquery 之节点操作
一.添加节点 [添加内部子节点方法]:内部节点就是儿子节点 append() 在被选元素内部的结尾插入内容 appendTo() 将指定内容插入到被选标签内部的结尾 prepend() 在 ...
- 2.MySQL 数据类型
MySQL 数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 数值类型 MySQL支持所有标准S ...