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. 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的更多相关文章
- 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 ...
- Gradle Goodness: Copy Files with Filtering
Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...
- Gradle Goodness: Task Output Annotations Create Directory Automatically
Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...
- 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 ...
- Gradle Goodness: Automatic Clean Tasks
Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This ...
- 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 ...
- 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. ...
- 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 ...
- 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 ...
随机推荐
- JDBC入门(5)--- 时间类型、大数据
一.时间类型 数据库类型与Java中类型的对应关系: DATE->java.sql.Date:表示日期,只有年月日,没有时分秒,会丢失时间. TIME->java.sql.Time:表示时 ...
- Berlekamp-Massey算法
\(BM\) 算法 用处 它可以用来求常系数线性递推的系数,并且可以求出最短的 求出来有什么用呢? 你可以闷声Cayley-Hamilton定理优化递推矩阵快速幂 算法简介 首先设一个数列 \(f\) ...
- 地图的平移、缩放的实现(android版)
一.平移地图 移动地图的原理是利用手指在屏幕上拖动的距离,转换为在地图上距离,把地图坐标加上偏移的距离实现地图移动. 由于地图是绘制到Bitmap上的,所以地图移动和缩放的过程只要改变Bitmap的矩 ...
- 基于SVM.NET的验证码识别算法实现
工作之余,对这个算法做了一些研究,并成功对验证码进行了识别,对普通验证码识别率在90%左右,识别速度相当快,已基于此做过一些自动查询.提交程序(例如投票.发帖等) ,还上过淘宝店,赚过一笔外快,现将相 ...
- Hive、Spark SQL、Impala比较
Hive.Spark SQL.Impala比较 Hive.Spark SQL和Impala三种分布式SQL查询引擎都是SQL-on-Hadoop解决方案,但又各有特点.前面已经讨论了Hi ...
- android OrmLite
最近在使用ormlite框架进行数据库的操作,下面简单的写个demo来学习下 1.下载jar包 这里使用的是ormlite-core-5.0.jar 和 ormlite-android-5.0.jar ...
- JS的Event Loop
JavaScript是单线程的,只有一个执行栈,一次只能做一件事. 在浏览器中,却“好像”可以同时做几件事:点击,发送请求,执行多个函数,解析代码. 这是因为浏览器实现的Event Loop机制. W ...
- Tomcat启动时卡在“INFO: Deploying web application directory ......”的解决方法
https://blog.csdn.net/njchenyi/article/details/46641141
- SQL SERVER占用CPU过高优化S
https://www.cnblogs.com/yuekong2010/p/6628001.html 然后使用下面语句看一下各项指标是否正常,是否有阻塞,正常情况下搜索结果应该为空. 1 SELECT ...
- Java笔记-IO流的运用
--如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3877386.html "谢谢-- 1.InputStream和System ...