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 ...
随机推荐
- vue的简单测试
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- mac关闭渐隐和弹出动画效果
苹果系统应用程序的窗口和对话框每次使用的时候都有华丽的特效,但是如果你感觉这种特效显得有点慢(MacGG闲的蛋疼),那该如何取消掉他呢? 方法很简单,打开"终端"(Finder-& ...
- 微服务架构之spring cloud gateway
Spring Cloud Gateway是spring cloud中起着非常重要的作用,是终端调用服务的入口,同时也是项目中每个服务对外暴露的统一口径,我们可以在网关中实现路径映射.权限验证.负载均衡 ...
- Python爬虫框架Scrapy教程(1)—入门
最近实验室的项目中有一个需求是这样的,需要爬取若干个(数目不小)网站发布的文章元数据(标题.时间.正文等).问题是这些网站都很老旧和小众,当然也不可能遵守 Microdata 这类标准.这时候所有网页 ...
- Two references point to the same heap memory
Phone类 package com.itheima_03; /* * 手机类 */ public class Phone { String brand; int price; String colo ...
- 《SQL必知必会》知识点汇总
select CustomerNo from dbo.Customers; 通配符的使用 select *from dbo.Customers; select CustomerNo from dbo. ...
- React学习笔记(七)条件渲染
React学习笔记(七) 六.条件渲染 使用if或条件运算符来创建表示当前状态的元素. 可以使用变量来存储元素.比如: let button = null; if (isLoggedIn) { but ...
- Centos7下面安装eclipse
下载Eclipse压缩包 下载路径 http://mirrors.neusoft.edu.cn/eclipse/technology/epp/downloads/release/luna/SR2/ec ...
- Vue中$refs的用法
说明:vm.$refs 一个对象,持有已注册过 ref 的所有子组件(或HTML元素) 使用:在 HTML元素 中,添加ref属性,然后在JS中通过vm.$refs.属性来获取 注意:如果获取的是一个 ...
- MS10-070 ASP.NET Padding Oracle信息泄露漏洞项目测试
MS10-070 ASP.NET Padding Oracle信息泄露漏洞1 漏洞描述:ASP.NET由于加密填充验证过程中处理错误不当,导致存在一个信息披露漏洞.成功利用此漏洞的攻击 ...