• Gradle Goodness: Copy Files with Filtering


    Gradle Goodness: Copy Files with Filtering

    Gradle's copy task is very powerful and includes filtering capabilities. This means we can change the contents of the files that are copied before they reach their new destination. We use the filter() method to define a filter. The good news is we can reuse the Ant filtering classes from the org.apache.tools.ant.filters package. We define the filtering class and can pass parameters for the filter. Or we can pass a closure which is passed each line as an argument. Within the closure we must return the filtered line.

    00.import org.apache.tools.ant.filters.*
    01. 
    02.task('filterCopy', type: Copy) {
    03.from 'src/templates'
    04.into buildDir
    05.include '**/*.txt'
    06.filter { line -> line.contains('Gradle') ? line : '' }
    07.filter(ReplaceTokens, tokens: [author: 'mrhaki', gradleVersion: gradle.gradleVersion])
    08.filter(ConcatFilter, prepend: file('src/include/header.txt'))
    09.}

    Now let's create a sample text file that will get filtered in src/templates/HelloGradle.txt:

    This is just a simple text file. This line will not make it.
    We show filtering capabilities of Gradle copy.
    This file is written by @author@ with Gradle version @gradleVersion@.

    And we create the file src/include/header.txt:

    Include this header file.
    -------------------------

    After we run $ gradle filterCopy we get the following contents for the file build/HelloGradle.txt:

    Include this header file.
    -------------------------
    We show filtering capabilities of Gradle copy in combination with the Ant filtering types.
    This file is written by mrhaki with Gradle version 0.9-rc-1.
  • 相关阅读:
    python数据库操作读书笔记
    python玩微信跳一跳实验报告
    制作自己的第一个网页
    python文件读写笔记
    Ethernet(以太网) 详解 MAC、MII、PHY
    Ethernet(以太网) 物理介质(10Base、100Base-T、100Base-TX等)
    QByteArray 转 QBitArray
    QT 线程应用
    QT release 发布打包压缩
    Qt中利用qDebug()记日志到文件
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4189101.html
Copyright © 2020-2023  润新知