Gradle Goodness: Rename Ant Task Names When Importing Ant Build File
Migrating from Ant to Gradle is very easy with the importBuild
method from AntBuilder
. We only have to add this single line and reference our existing Ant build XML file and all Ant tasks can now be executed as Gradle tasks. We can automatically rename the Ant tasks if we want to avoid task name collisions with Gradle task names. We use a closure argument with the importBuild
method and return the new task names. The existing Ant task name is the first argument of the closure.
Let's first create a simple Ant build.xml
file:
00.
<
project
>
01.
02.
<
target
name
=
"showMessage"
03.
description
=
"Show simple message"
>
04.
05.
<
echo
message
=
"Running Ant task 'showMessage'"
/>
06.
07.
</
target
>
08.
09.
<
target
name
=
"showAnotherMessage"
10.
depends
=
"showMessage"
11.
description
=
"Show another simple message"
>
12.
13.
<
echo
message
=
"Running Ant task 'showAnotherMessage'"
/>
14.
15.
</
target
>
16.
17.
</
project
>
The build file contains two targets: showMessage
and showAnotherMessage
with a task dependency. We have the next example Gradle build file to use these Ant tasks and prefix the original Ant task names with ant-
:
00.
// Import Ant build and
01.
// prefix all task names with
02.
// 'ant-'.
03.
ant.importBuild(
'build.xml'
) { antTaskName ->
04.
"ant-${antTaskName}"
.toString()
05.
}
06.
07.
// Set group property for all
08.
// Ant tasks.
09.
tasks.matching { task ->
10.
task.name.startsWith(
'ant-'
)
11.
}*.group =
'Ant'
We can run the tasks
task to see if the Ant tasks are imported and renamed:
$ gradle tasks --all
...
Ant tasks
---------
ant-showAnotherMessage - Show another simple message [ant-showMessage]
ant-showMessage - Show simple message
...
$
We can execute the ant-showAnotherMessage
task and we get the following output:
00.
$ gradle ant-showAnotherMessage
01.
:ant-showMessage
02.
[ant:echo] Running Ant task
'showMessage'
03.
:ant-showAnotherMessage
04.
[ant:echo] Running Ant task
'showAnotherMessage'
05.
06.
BUILD SUCCESSFUL
07.
08.
Total time:
3.953
secs
09.
$
Written with Gradle 2.2.1
Gradle Goodness: Rename Ant Task Names When Importing Ant Build File的更多相关文章
- Gradle Goodness: Task Output Annotations Create Directory Automatically
Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...
- Gradle Goodness: Check Task Dependencies With a Dry Run
We can run a Gradle build without any of the task actions being executed. This is a so-called dry ru ...
- Gradle Goodness: Working with Live Task Collection
Gradle support the definition of so called live collections. These collections are mostly created ba ...
- Gradle Goodness: Copy Files with Filtering
Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...
- 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: Adding Tasks to a Predefined Group
In Gradle we can group related tasks using the group property of a task. We provide the name of our ...
- 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学习之创建Task的方法
请通过下面方式下载本系列文章的Github演示样例代码: git clone https://github.com/davenkin/gradle-learning.git Gradle的Pr ...
- Gradle 使用教程之 Task 详解
最近打算学习下 gradle 在 Android 中的使用,结果百度出来的文章都是介绍性文章,没啥干货.后来找到 gradle 官网教程,自己对着撸. Gradle 概述: Gradle 是一个基于 ...
随机推荐
- iis7应用程序池自动关闭问题解决
解决: 应用程序池启动32位应用程序 设置托管管道为集成 (仍然有问题) 图片:123.png 访问网站之前 应用程序池是开启的 访问后 网页报503 service unavailable应用程序池 ...
- Visio编辑数据库模型列
Visio编辑数据库模型列:邮件group->Open实体,进入实体属性编辑界面,按回车可以添加.
- 设置xx-net,访问youtube等国外网站
配合使用chrome+xx-net,就可以免费访问youtube等外网了.步骤如下: 1. 按照https://github.com/XX-net/XX-Net/wiki/%E4%BD%BF%E7%9 ...
- C++类中的this指针的作用
1.我们知道C++的类成员函数中,默认都隐含了一个this指针,标识调用该成员函数的对象 2.为什么需要有一个this指针呢?C++设计这个机制的初衷是什么呢? 我们知道,普通的C++类,其成员函数是 ...
- 搭建SpringMVC+MyBatis开发框架一
大部分 Java 应用都是 Web 应用,展现层是 Web 应用不可忽略的重要环节.Spring 为展现层提供了一个优秀的 Web 框架—— Spring MVC.和众多其他 Web 框架一样,它基于 ...
- Kibana4学习<二>
生产环境部署 Kibana4 是是一个完整的 web 应用.使用时,你需要做的只是打开浏览器,然后输入你运行 Kibana 的机器地址然后加上端口号.比如说:localhost:5601 或者 htt ...
- Careercup - Google面试题 - 6271724635029504
2014-05-06 13:23 题目链接 原题: Finding a pair of elements from two sorted lists(or array) for which the s ...
- android listview和button,ImageButton等有事件的控件的总结
public ImageButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defSty ...
- Upgrading to Java 8——第三章 Optional and Similar Classes
Java程序员对付空指针异常已经好多年了.在Java8中将有新的方式去处理他们.通过包装一个潜在的可能为null的类称为Optianal. 在Java8中添加了the Optional, Option ...
- windows python 打印utf-8乱码
从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...