ant - How to invoke a macrodef from within another file -
i wrote small macrodef in separate file:
macrodefs.xml
<macrodef name="do-cool-stuff"> <attribute name="message"/> <sequential> <echo message="@{message}" /> </sequential> </macrodef>
i got second file, main build file:
build.xml
<target name="build"> <!-- , --> <!-- cheking out macrodefs.xml via cvs --> <ant antfile="macrodefs.xml" target="do-cool-stuff" > <property name="message" value="hello, world!" /> </ant> </target>
as might guess dosen't work. error message like:
target 'do-cool-stuff' not exist in project.
the possible solution found provide target in macrodefs.xml forward ant calls.
is there possibility invoke macrodef within file?
thanks in advance.
you can import
file , use macro this:
<import file="macrodefs.xml" /> <do-cool-stuff message="hello, world!" />
note in macro definition should use @{curlybrackets}
when referencing macro attributes:
<sequential> <echo message="@{message}" /> </sequential>
there examples @ end of ant macrodef
task docs.
more
what you're trying isn't supported ant. ant
, antcall
tasks don't allow 'callee' affect caller directly. can write files in called task, load in caller. have observed, pre-process tasks import
, include
cannot called within target. ant/antcall tasks allow run targets in subsidiary builds, not macros.
one workaround method (this might similar 1 mention, allows put real work in top-level build) have inner buildfile includes top-level import of macrodefs.xml.
something following. macrodefs.xml file before. (but note imported files - including macro definitions - need complete ant project files, must include project element.)
build.xml:
<target name="build"> <!-- cvs actions --> <ant antfile="inner-build.xml" target="target-runner"> <property name="target" value="top-target" /> </ant> </target> <!-- target fail unless invoked inner build --> <target name="top-target"> <do-cool-stuff message="hello, world!" /> </target>
inner-build.xml:
<project> <import file="macrodefs.xml" /> <target name="target-runner"> <ant antfile="build.xml" target="${target}" /> </target> </project>
effectively doing
build.xml --> inner-build.xml --> build.xml (again) (cvs) (import macros) (use macros)
the inner buildfile potentially generated on-the-fly main build - if wanted import multiple macro definition files - that's getting perhaps unwieldy.
Comments
Post a Comment