Converting Gradle FileColletions into Ant FileSets


As part of our incremental conversion from Ant to Gradle I need to be able to use Gradle to set some global ant filesets. Setting a property works just fine.

I have tried 2 approaches on the Gradle side:

  1. ant.references.put(“testxFileset”, basePath.files), but then ant tells me this is not a fileset.
  2. basePath.addToAntBuilder(project.ant, ‘ant’, FileCollection$AntType.FileSet), but I’m not sure what to put for the nodeName here , ‘ant’ does not work.

Here is my sample code:
Gradle Script:

ant.importBuild 'build.xml'

def FileCollection basePath = files(fileTree(dir: '../tools/ant/lib', include: '*.jar'))
def testProp = "88"

echoValues { = testProp  //Sets an ant property prior to calling the target.
  basePath.addToAntBuilder(project.ant, 'ant', FileCollection$AntType.FileSet)
  //ant.references.put("testxFileset", basePath.files)

  println "testxProp=" +"testxProp")
  println "testxFileset=" + ant.references.get("testxFileset")

Ant script:

<project name="sandbox" basedir=".">
      <target name="echoValues">
        <echo message="${testxProp}"/>
        <foreach target="bar" param="theFile">
            <fileset refid="testxFileset"/>
    <target name="bar">
        <echo message="${theFile}"/>

Any help would be appreciated.