863

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

Question:

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?

Answer1:

According to the <a href="http://groovy.codehaus.org/The+groovy+Ant+Task" rel="nofollow" title="Groovy Ant Task">Groovy Ant Task</a> documentation, one of the <strong><em>bindings</em></strong> for the groovy task is the current <em>AntBuilder</em>, 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>

Recommend

  • Python: get the return code of ant sub-process in windows
  • Connecting to an HTTPS service with SproutCore
  • How can I reuse an SQL fragment with parameters?
  • Duplicate Data Stop in MySQL
  • Gemfire Persistent Overflow
  • componentdef error with ant
  • Unable to get Emma Coverage for Android [duplicate]
  • HTML5 video only works in IE. The other browsers shows the black screen
  • MeeGo Handset Emulator not starting on Windows 7
  • C++ friend class std::vector
  • Knockout custom binding handler
  • Using $compile in a directive triggers AngularJS infinite digest error
  • How to make Twilio api Post request with the help of AFNetworking?
  • Unable to send e-mail through Java
  • didUpdatePushCredentials not get called
  • UIAlertController button function not working
  • SetWindowsHookEx does not react on media keys
  • Element.tagName for python not working
  • List images(01.png) and descriptions(01.txt) from directory
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • Copy to all folders batch file?
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • Install PHP intl extension on MacOS
  • Grails calculated field in SQL
  • Retrieve list of sent friend requests from friend_request FQL table
  • How to test if a URL from an Eclipse bundle is a directory?
  • NHibernate Validation Localization with S#arp Architecture
  • How can I send an e-mail from a vbs script
  • Accessing IRQ description array within a module and displaying action names
  • How to add date and time under each post in guestbook in google app engine
  • JSON with duplicate key names losing information when parsed
  • Return words with double consecutive letters
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Getting Messege Twice Using IMvxMessenger
  • How to stop GridView from loading again when I press back button?
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass