tags:

views:

492

answers:

1

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  A: 

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>
Ken Gentle