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 ...
随机推荐
- 2806 红与黑 个人博客:doubleq.win
个人博客:doubleq.win 2806 红与黑 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Descripti ...
- H5实现拍照上传功能
<input type="file" capture="camera" accept="image/*" >
- ionic--分模块
1. app.js var app=angular.module("myApp",["ionic","myController"," ...
- JS cookie 设置 查看 删除
JScookie 常用的3个预设函数(库) <!DOCTYPE HTML> <html> <head> <meta charset="utf-8&q ...
- vue-cli构建项目 npm run build后应该怎么运行在本地查看效果
问题: 就是 bulid 打包后,想本地看看效果,本地看不了.... 网上看到一个.... 具体更多在: http://www.dabaipm.cn/static/frontend/346.htm ...
- Maven-pom-configuration
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- VC学习笔记---ATL MFC CLR三个库的区别
MFC.ATL和CLR是VC2005内置的三大库,涵盖了Windows的各种开发方法和开发应用.当然关于C++开发的库不止这三个,不过这三个是微软推荐. 从编程所处层次而言,WIN32为最底层,其次是 ...
- Maximum Subarray 连续子数组最大和
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- mac下 安装tomcat 后项目无法启动以及 错误 找不到或无法加载主类
按照网上的步骤,在mac上安装tomcat后,写个简单的测试类报错:错误 找不到或无法加载主类 Class JavaLaunchHelper is implemented in both /Libra ...
- C# winform中 窗体缩放自适应的方法(不同电脑/不同分辨率)
C# winform中 窗体缩放自适应的方法(不同电脑/不同分辨率) 窗体缩放是一个困扰我多时的问题,为了解决这个问题,我从网上找了很多相关的资料,很多人说用Anchor和Dock属性,但是我试了 ...