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 ...
随机推荐
- css实现中间文字,两边横线效果
1. vertical-align属性实现效果: vertical-align 属性设置元素的垂直对齐方式. 该属性定义行内元素的基线相对于该元素所在行的基线的垂直对齐.允许指定负长度值和百分比值. ...
- 洛谷P3939 数颜色(二分 vector)
题意 题目链接 Sol 直接拿vector维护每种颜色的出现位置,然后二分一下. #include<bits/stdc++.h> using namespace std; const in ...
- input一些验证
这篇博文大部分来自于网上,为了方便自己查阅,以及帮助他人. 1.正则验证只能输入正整数: onkeyup = " if (this.value.length==1) { this.valu ...
- canvas toDataURL() 方法如何生成部分画布内容的图片
HTMLCanvasElement.toDataURL() 方法返回一个包含图片展示的 data URI .可以使用 type参数其类型,默认为 PNG 格式.图片的分辨率为96dpi. 如果画布的高 ...
- html技巧
1.防止盒子透出的解决办法 overflow:hidden:float不为none:display:inline-block: position不为static&relative ...
- 关于webpack 配置文件找不到
运行命令 npm run eject 将配置文件解压出来 如果运行这个命令有错的时候,很可能与 git 有关 这时候,打开项目文件夹,显示所有隐藏的文件夹(工具),如果显示了git 的文件夹 删掉 ...
- jquery-animate()动画
一.animate()语法 $(“选择器”).animate({CSS样式},时间,运动方式,回调函数); 参数说明: 参数1:CSS属性名,属性值,JSON格式{"属性名":&q ...
- 对数损失函数(Logarithmic Loss Function)的原理和 Python 实现
原理 对数损失, 即对数似然损失(Log-likelihood Loss), 也称逻辑斯谛回归损失(Logistic Loss)或交叉熵损失(cross-entropy Loss), 是在概率估计上定 ...
- SVN的正确提交方式
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Rundy_Deng/article/details/80338093 也会让我们百思不得其解,甚至耽 ...
- C#-XML-数据传输
http://www.cnblogs.com/fengxuehuanlin/p/5631664.html 关于xml是属于一个比较重要的东西,在平时开发的过程中,这块内容最主要的是要掌握XML内容的读 ...