How to <copy> in <macro definition> in ant?

I am trying to copy files to a macro, for example:

<project name="why" default="go">
  <macrodef name="copy-some-stuff">
    <attribute name="file.name" />

    <copy todir="/var/tmp">
      <fileset file="${file.name}" />
    </copy>
  </macrodef>

  <target name="go">
    <copy-some-stuff file.name="/etc/hosts" />
  </target>
</project>

but i get the following

BUILD FAILED
b.xml:3: macrodef doesn't support the nested "copy" element.

Any ideas except yes, indeeed, macrodef do not support the nested copy element. I got so much. I am looking for why this limitation is here and a possible workaround (without use antcall).

+5
source share
1 answer

Try to surround the element <copy> <sequential>:

<macrodef name="copy-some-stuff">
   <attribute name="file.name" />
   <sequential>
      <copy todir="/var/tmp">
          <fileset file="@{file.name}" />
      </copy>
   </sequential>
</macrodef>
+9
source

All Articles