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. Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils

    关键词:IntelliJ IDEA.Tomcat.commons-io-2.5.jar.java.lang.ClassNotFoundException: org.apache.commons.io. ...

  2. 用fritzing绘制arduino硬件连线图

    在http://fritzing.org/home/ 点击下载最新版本. 解压之后直接可以使用. 打开Fritzing.exe 在点击面包板,在搜索界面输入想要找到的原件拖拽即可放在面包板所在的图上. ...

  3. HTML 5 教程

    HTML5 是下一代的 HTML.有必要再过一遍.看下要点. 具体看  http://www.w3school.com.cn/html5/index.asp    教程 和  HTML5 标签参考手册 ...

  4. SVN - Checksum mismatch while updating

    Go to the folder with the file causing problems Execute command svn update --set-depth empty (note: ...

  5. 编辑文本(EditText)

    今天要给大家介绍的是简单的编辑文本框: 先看一下它的基本属性: 1.Activity public class EditTextActivity extends Activity { private ...

  6. ArcGIS最权威、最专业的技术分享网站:积思园(www.iarcgis.com)

    你对iArcGIS.com说点什么 为什么会有该网站的产生 在这个所谓的“大数据”的时代,每个人都深陷于海量信息无法自拔,因为过多碎片化的数据只会让自己的思维更加迷离,快餐式的阅读只会让自己变得虚胖. ...

  7. 131.006 Unsupervised Learning - Feature Scaling | 非监督学习 - 特征缩放

    @(131 - Machine Learning | 机器学习) 1 Feature Scaling transforms features to have range [0,1] according ...

  8. 2.bootstrap安装

    1.下载 您可以从 http://getbootstrap.com/ 上下载 Bootstrap 的最新版本(或者 http://www.bootcss.com/  中文网) Download Boo ...

  9. 基于bootstrap的模态框的comfirm弹窗

    完成的效果如下: html代码如下: <button id="btn">点击弹出弹框</button> <!-- 弹出框 --> <div ...

  10. Qt Mysql驱动编译过程

    1.首先当然是要有VS2008+Qt4.7的开发环境. 2.安装MySQL,最好是4以后的版本,安装MySQL时要勾住“C Include Files 和 Lib Files”选项,这样才能装上MyS ...