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.

Gradle Goodness: Copy Files with Filtering的更多相关文章

  1. Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task

    With the copy task of Gradle we can copy files that are parsed by Groovy's SimpleTemplateEngine. Thi ...

  2. Gradle Goodness: Renaming Files while Copying

    With the Gradle copy task we can define renaming rules for the files that are copied. We use the ren ...

  3. Gradle Goodness: Task Output Annotations Create Directory Automatically

    Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...

  4. Xcode6 ADD Copy Files Build Phase 是灰色的

    在学习的怎样写frameWork的时候,查看一个教程How to Create a Framework for iOS  [一个中文翻译 创建自己的framework] 其中一个步骤就是添加一个Cop ...

  5. How to copy files between sites using JavaScript REST in Office365 / SharePoint 2013

    http://techmikael.blogspot.in/2013/07/how-to-copy-files-between-sites-using.html I'm currently playi ...

  6. How do I copy files that need root access with scp

    server - How do I copy files that need root access with scp? - Ask Ubuntuhttps://askubuntu.com/quest ...

  7. 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. ...

  8. 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 ...

  9. Could not resolve all files for configuration;Andriod在build.gradle添加compile files()报错

    在build.gradle中添加个 compile files('libs/alipaySdk-20170922.jar') 就一直报这个错误 Error:Could not resolve all ...

随机推荐

  1. 判断是手机端还是电脑端 isMobile()

    1.在PublicController控制器中写好判断手机端方法. <?php namespace Home\Controller; use Think\Controller; class Pu ...

  2. 测试canvas绘制旋转文字的性能

    canvas 绘制各种动画效果时,我们经常会使用画布旋转,使绘制上去的元素有旋转的效果. 最近在项目中碰到了很严重的性能问题,经常排查发现是因为绘制批量文字时使用了画布旋转,且每行文字的旋转角度是不一 ...

  3. 转 VS Code 快捷键大全,没有更全

    VS Code折腾记 - (2) 快捷键大全,没有更全 前言 VSCode的快捷键继承了一些IDE风格,有VS的身影,也有Emacs的身影..简言之,内置快捷键玩熟了,效率提高不是一点两点. VsCo ...

  4. plan,idea,and dream

    自学机器学习/数据分析/前端 目前想法是从前端入手,学会写/分析网页及其内容/数据,然后使用爬虫爬取数据,然后用机器学习算法对数据进行处理.哈哈,想法是不是太天真了. 学习都从网上的资料入手,因此发现 ...

  5. Architecture And Framework

    高屋建瓴 From Up to Down. Outside into inside. Interface-Oriented Framework with dynamic configuration. ...

  6. 安卓app开发-03-项目的基本开发步骤

    android项目的基本开发步骤 这里分享一下开发 安卓 app 的流程,当然有些感觉不必要,其实不然,前期工作也是极为重要的额,就像开发的时候如果目标不对的话,到后期后很迷的,所以一定要提前做好规划 ...

  7. Android深入四大组件(五)Android8.0 根Activity启动过程(后篇)

    前言 在几个月前我写了Android深入四大组件(一)应用程序启动过程(前篇)和Android深入四大组件(一)应用程序启动过程(后篇)这两篇文章,它们都是基于Android 7.0,当我开始阅读An ...

  8. token 和 服务器端auth0-JWT包的使用

    移动客户端和服务器端在用户登录上经常使用的是一个叫做token的认证方法 token是什么? token顾名思义, 令牌, 意思就是说,第一次用户登录验证之后,服务器返回一个token令牌,之后客户端 ...

  9. leetcode Ch1-Search

    一. Binary Search int binarySearch(vector<int> &array, int target) { , hi = array.size() - ...

  10. 图书管理系统 基于form组件

    models: from django.db import models # Create your models here. class Book(models.Model): name = mod ...