我似乎找不到一种方法从我的Gradle脚本中列出和/或调用Ant宏。关于宏防御的分级用户指南会谈,但是这里没有提供一个例子。有人能告诉我如何做到这一点吗?
目前,我通过执行ant.importBuild任务导入Ant构建。这很好,因为Ant目标显示为Gradle任务。但是,我无法列出和/或调用Ant构建中所述的Ant宏。有人能给我答案吗?
发布于 2015-05-07 08:39:10
你的build.xml
<project name="test">
<macrodef name="sayHello">
<attribute name="name"/>
<sequential>
<echo message="hello @{name}" />
</sequential>
</macrodef>
</project>和build.gradle
ant.importBuild 'build.xml'
task hello << {
ant.sayHello(name: 'darling')
}让我们来测试一下
/cygdrive/c/temp/gradle>gradle hello
:hello
[ant:echo] hello darling
BUILD SUCCESSFUL
Total time: 2.487 secs发布于 2015-08-31 16:53:03
Ant允许不适合Groovy的标识符限制的宏名称。如果是这样的话,显式的invokeMethod调用可能会有所帮助。给予:
<project name="test">
<macrodef name="sayHello-with-dashes">
<attribute name="name"/>
<sequential>
<echo message="hello @{name}" />
</sequential>
</macrodef>
</project>这会起作用的
ant.importBuild 'build.xml'
task hello << {
ant.invokeMethod('sayHello-with-dashes', [name: 'darling'])
}https://stackoverflow.com/questions/30094857
复制相似问题