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. idea新建maven多模块spring boot项目

    1.新建一个maven多模块项目,比如这种结构: maven-demo |--demo-common |--demo-order |--demo-user 2.先新建一个maven项目,在maven项 ...

  2. JavaScript & jQuery & Bootstrap

    一.前言 javascript 简称 JS  与java编程语言 没有什么关系 JavaScript: {核心(ECMAScript) 文档对象模型(DOM) Document object mode ...

  3. VC++中如何将字符串转换成整型数字

    原文:http://blog.csdn.net/yongf2014/article/details/47071663 注意: atoi函数是c的函数,它的输入参数是char *类型. 你声明了stri ...

  4. [学习] nofollow

    [来源:百度百科 http://baike.baidu.com/view/1584081.htm] 简介 nofollow[1]是一个HTML标签的属性值.它的出现为网站管理员提供了一种方式,即告诉搜 ...

  5. IDEA Properties中文unicode转码问题

    在IDEA中创建了properties文件,发现默认中文不会自动进行unicode转码.如下 在project settings - File Encoding,在标红的选项上打上勾,确定即可 效果图 ...

  6. JDK1.7环境

    官方下载页面: http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-52126 ...

  7. mysql索引小记

    Mysql索引分为以下几类:FULLTEXT, HASH,BTREE,RTREE. FULLTEXT:全文搜索索引 主要是解决'ad%'这样的查询效率低的问题,只能是MyISAM和InnoDB引擎上使 ...

  8. 利用.NET Core类库System.Reflection.DispatchProxy实现简易Aop

    背景 Aop即是面向切面编程,众多Aop框架里Castle是最为人所知的,另外还有死去的Spring.NET,当然,.NET Core社区新秀AspectCore在性能与功能上都非常优秀,已经逐渐被社 ...

  9. 深入浅出SharePoint——使用WinDbg进行调试

  10. c# winform文本框数字,数值校验

    文本框数字,数值校验 public void DigitCheck_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = !char.I ...