翻译项目请关注Github上的地址:
https://github.com/msdx/gradledoc
本文翻译所在分支:
https://github.com/msdx/gradledoc/tree/2.0 。
6.10. 使用 Ant 任务
https://github.com/msdx/gradledoc
本文翻译所在分支:
https://github.com/msdx/gradledoc/tree/2.0 。
6.10. 使用 Ant 任务
6.10. Using Ant Tasks
Ant任务是Gradle的一级公民。Gradle通过简单地依赖Groovy,对Ant任务提供了强大的集成。Groovy自带了一个神奇的AntBuilder
,在Gradle中使用Ant任务比在build.xml
中调用更方便和强大。通过下面的例子,您可以学习到如何执行ant任务,以及如何访问ant属性:
Ant tasks are first-class citizens in Gradle. Gradle provides excellent integration for Ant tasks by simply relying on Groovy. Groovy is shipped with the fantastic AntBuilder
. Using Ant tasks from Gradle is as convenient and more powerful than using Ant tasks from a build.xml
file. From the example below, you can learn how to execute ant tasks and how to access ant properties:
示例6.13. 使用AntBuilder 执行 ant.loadfile 目标 - Example 6.13. Using AntBuilder to execute ant.loadfile target
build.gradle
task loadfile << { def files = file('../antLoadfileResources').listFiles().sort() files.each { File file -> if (file.isFile()) { ant.loadfile(srcFile: file, property: file.name) println " *** $file.name ***" println "${ant.properties[file.name]}" } } }
gradle -q loadfile
的输出结果
Output of gradle -q loadfile
> gradle -q loadfile *** agile.manifesto.txt *** Individuals and interactions over processes and tools Working software over comprehensive documentation Customer collaboration over contract negotiation Responding to change over following a plan *** gradle.manifesto.txt *** Make the impossible possible, make the possible easy and make the easy elegant. (inspired by Moshe Feldenkrais)