ant 中的 groovy:如何从 ant 标签定义的 grooy 访问 refids [英] groovy inside ant: how to access refids from grooy that are defined by ant tags

查看:22
本文介绍了ant 中的 groovy:如何从 ant 标签定义的 grooy 访问 refids的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ant 构建文件中使用了一个 groovy 代码片段.在 groovy 代码中,我试图引用在 groovy 部分之外定义的文件集,如下所示:

I'm using a groovy code snippet in an ant build file. Inside the groovy code I'm trying to reference a fileset that has been defined outside of the groovy part, like this:

<target name="listSourceFiles" >
    <fileset id="myfileset" dir="${my.dir}">
         <patternset refid="mypatterns"/>
    </fileset>
    <groovy>
        def ant = new AntBuilder()

        scanner = ant.fileScanner {
            fileset(refid:"myfileset")
        }

    ...
    </groovy>
</target>

执行此操作时,我收到以下错误消息:

When I execute this I get the following error message:

Buildfile: build.xml

listSourceFiles:   
   [groovy]

BUILD FAILED
d:\workspace\Project\ant\build.xml:13:
Reference myfileset not found.

我错过了什么?

推荐答案

根据 Groovy Ant Task 文档,groovy 任务的 绑定 之一是当前的 AntBuilder蚂蚁.

According to the Groovy Ant Task documentation, one of the bindings for the groovy task is the current AntBuilder, ant.

所以修改你的脚本以删除冲突的蚂蚁"定义我让它运行没有错误:

So modifying your script to drop the clashing 'ant' def I got it to run with no errors:

<project name="groovy-build" default="listSourceFiles">

<taskdef name="groovy"
         classname="org.codehaus.groovy.ant.Groovy"/>

<patternset id="mypatterns">
  <include name="../*.groovy"/>
</patternset>
<target name="listSourceFiles" >
    <fileset id="myfileset" dir="${my.dir}">
         <patternset refid="mypatterns"/>
    </fileset>
    <groovy>
        scanner = ant.fileScanner {
            fileset(refid:"myfileset")
        }
    </groovy>
</target>
</project>

这篇关于ant 中的 groovy:如何从 ant 标签定义的 grooy 访问 refids的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆