With the copy task of Gradle we can copy files that are parsed by Groovy's SimpleTemplateEngine. This means we can expand properties in the source file and add Groovy code that is going to be executed. We must use the expand() method in the copy task where we can pass properties to be used in the source file.

00.version = 'DEMO'
01.group = 'com.mrhaki'
02. 
03.task copy(type: Copy) {
04.from 'src/templates'
05.into "$buildDir"
06.include 'projectinfo.html.template'
07.rename { file -> 'projectinfo.html' }
08.expand(project: project, title: 'ProjectInfo', generated: new Date())
09.}

We define the following source file in src/templates/projectinfo.html.template:

00.<html>
01.<head>
02.<title>${title}</title>
03.</head>
04.<body>
05.<h1>${project.name}</h1>
06. 
07.<ul>
08.<% project.properties.findAll { k,v -> v instanceof String }.each { key, value -> %>
09.<li>$key = $value</li>
10.<% } %>
11.</ul>
12. 
13.<hr />
14.<p>Generated on ${generated.format('dd-MM-yyyy')}</p>
15.</body>
16.</html>

When we run the copy task we get the following output:

Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task的更多相关文章

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

  2. Gradle Goodness: Copy Files with Filtering

    Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...

  3. Gradle Goodness: Task Output Annotations Create Directory Automatically

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

  4. Gradle Goodness: Add Incremental Build Support to Tasks

    Gradle has a very powerful incremental build feature. This means Gradle will not execute a task unle ...

  5. Gradle Goodness: Automatic Clean Tasks

    Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This ...

  6. Gradle Goodness: Unpacking an Archive

    To create an archive with Gradle is easy. We have several tasks like Zip, Tar, Jar, War and Ear to c ...

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

  9. Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/lidroid/xutils/task/TaskHandler;

    Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files defi ...

随机推荐

  1. Working C# code for MySql5.5 Stored Procedures IN parameters

    MySQL5.5存储过程: #插入一条 涂聚文 DELIMITER $$ DROP PROCEDURE IF EXISTS `geovindu`.`proc_Insert_BookKindList` ...

  2. USACO08MAR土地购买 与 APIO2010特别行动队

    两道斜率优化DP: 土地购买 约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地.如果约翰单买一块土 地,价格就是土地的面积.但他可以选择并购一组土地,并购的价格为这些土地中最大的长 乘以最大的 ...

  3. git忽略相应文件夹,不上传

    1.在项目根目录里  右键选择Git Bash 进入命令行 2. touch .gitignore ,生成“.gitignore”文件. 3.  .gitignore文件里输入以下内容.DS_Stor ...

  4. c# 序列化接口(转载贴)

    http://www.cnblogs.com/TianFang/p/3724449.html

  5. RHEL生命周期管理 -- Should I stay, or should I go?

    1. RHEL的支持策略是怎么样的? 标准支持(一般7年)+ 延长支持(3年) 2. 升级RHEL的好处有哪些? More advantageous to upgrade completely to ...

  6. Sqlserver函数基础使用

    函数基本功能: 转换工厂日期,将8点20之前的时间转化为前一天的时间. if exists (select * from sysobjects where xtype='fn' and name='F ...

  7. NexusFile(文件管理器)

    NexusFile是一款来自于韩国的文件管理器,类似于TotalCommander,拥有两个并排的文件夹窗口. NexusFile软件的特性如下: 基本功能:复制/移动, 复制/剪切/粘贴, 删除/擦 ...

  8. Linux who命令详解

    who 命令显示关于当前在本地系统上的所有用户的信息.显示以下内容:登录名.tty.登录日期和时间.输入whoami 显示您的登录名.tty.您登录的日期和时间.如果用户是从一个远程机器登录的,那么该 ...

  9. Java代码实现对Azkaban的Flow进行设置定时

    代码如下: public class CurlToAzkaban{ public static void scheduleExecute(String flow, String cronExpress ...

  10. excel展示