将 build.xml 转换为 build.groovy

Converting build.xml to build.groovy

我正在尝试通过完全消除 Build.xml 将 build.xml(在我的 Ant 项目中使用)完全转换为 Groovy 脚本。

基本上,我想要实现的是 Build.xml ---> Build.groovy.

我在尝试这样做时有以下疑问。

1) 如何在我的 groovy 脚本中将 macrodef 转换为函数

<macrodef name="build.record">
         <attribute name="log.file"/>
         <attribute name="action"/>
         <sequential>
                 <echo message="starting build4.record with file name @{log.file} and action @{action}" />
                 <record name="@{log.file}" action="@{action}" loglevel="verbose" />
         </sequential>
     </macrodef>

我知道可以通过使用 groovy.util.AntBuilder.sequential 实现连续性 如何在我的脚本中将 macrodef 作为一个整体转换为 groovy 函数?

2) 如何在我的 groovy 脚本中创建 Ant JavaDoc?

像那样? (你可以用百万种方式做到这一点..)

def ant = new AntBuilder()

def buildRecord={Map attr->
    ant.echo(message: "starting build4.record with file name ${attr['log.file']} and action ${attr.action}" )
    ant.record(name: "${attr['log.file']}", action: "${attr.action}", loglevel:"verbose" )
}

ant.echo(message:"start")
buildRecord('log.file': "myfile", action: "myaction")
ant.javadoc(sourcepath: "...", "destdir": "...")

并查看 gradle 构建工具,您可以在其中使用上述 AntBuilder groovy 写入