groovy inside ant: how to access refids from grooy that are defined by ant tags

不问归期 提交于 2019-12-24 18:35:36

问题


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.

What am I missing?


回答1:


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>


来源:https://stackoverflow.com/questions/225063/groovy-inside-ant-how-to-access-refids-from-grooy-that-are-defined-by-ant-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!