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. Redis ,Memcached ,Mongodb 对比

    memcached: 1.适合做内存缓存,对可靠性没有要求,不支持持久化:速度快.并发高.2.支持的数据结构单一,只支持Key-value,3.value最大支持1M3.在传统tomcat 部署war ...

  2. csharp: Gets a files formatted size.

    /* ASP.NET 默认上传文件是4M ,可以修改服务配置.. <system.web> <!-- 指示 ASP.NET 支持的最大文件上载大小. 该限制可用于防止因用户将大量文件 ...

  3. 【HTML基础】<acronym>和<abbr>的区别

    缩写标签<acronym> <abbr>的区别 大家都知道HTML定义缩写有<acronym> <abbr>两种标签,但是经常分不清楚他们.这两个标签虽 ...

  4. Java 开源博客 Solo 1.6.0 发布 - 新后台

    简介 Solo 是一款一个命令就能搭建好的 Java 开源博客系统,并内置了 15+ 套精心制作的皮肤.除此之外,Solo 还有着非常活跃的社区,文章分享到社区后可以让很多人看到,产生丰富的交流互动. ...

  5. 解决API中无法使用session问题

    处理API无法使用session的方法,贴图: 1调用如下图 2.需要在Global.asax文件中配置一些东西 protected void Application_PostAuthorizeReq ...

  6. HTTP状态码和HTTP请求头

    HTTP报文是在Web服务器和浏览器之间进行交换的文本数据,一种是从浏览器发出的请求,一种是服务器发出的响应. 请求报文的第一行包括:1.请求方法 2.当前使用的HTTP协议版本 3.请求地址 GET ...

  7. VS2010 创建 windows service 程序

    参考网上保护眼睛程序,自写程序如下. 1.创建一个名词为“CareEyeService”,类型为“WindowsService”的应用程序. 自动生成代码如下图: 2.修改ServiceCareEye ...

  8. js 正则常用函数

    正则表达式中,需要转义的字符: * . ? + $ ^ [ ] ( ) { } | \ / let reg = /\d+/g let str = 'ad/23/dfww/454/6' 1. reg.t ...

  9. Django 简单教程(入门级)

    一.Django简介 1. web框架介绍 具体介绍Django之前,必须先介绍WEB框架等概念. web框架: 别人已经设定好的一个web网站模板,你学习它的规则,然后“填空”或“修改”成你自己需要 ...

  10. VS无法加载Web项目

    在VS中修改Web项目的服务器设置时无法加载改Web项目,提示如下图 原因:因为项目中的EbcBuy.Bll.Users.WebApi.csproj.user文件并没有加入到版本控制文件,所以讲项目还 ...