zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    洛谷 P1850 换教室(期望dp)
    简单异或 && 洛谷 P1469 找筷子 && 洛谷 P3908 数列之异或
    2020 CSP-J复赛题解
    2018 ICPC 南京 D Country Meow(模拟退火|三分)
    佩尔方程
    块速幂/光速幂
    1436F
    反Nim游戏
    P1447 [NOI2010]能量采集(莫比乌斯反演)
    P3768 简单的数学题 (莫比乌斯反演+杜教筛)
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4189143.html
Copyright © 2011-2022 走看看