antmacrodef

How do I call an Ant macro from inside another macrodef?


I have a build.xml, from here I call a macro:

<import file="macro_file.xml" />
<ant-macro message="Hello, World!" />

and my macro_file.xml file looks like this:

<macrodef name="ant-macro">
    <attributes name="message"/>
    <sequential>
        <echo message="@{message}" />
    </sequential>
</macrodef>

How can I call another macro inside the ant-macro macro?

I tried in the below manner, but its gives an error.

<macrodef name="ant-macro">
    <attributes name="message"/>
    <second-macro messge="hi"/>
    <sequential>
        <echo message="@{message}" />
    </sequential>
</macrodef>

The second-macro macro is also defined in the macro_file.xml file.


Solution

  • The macro executes everything inside its sequential element. Just put your second-macro call inside it:

    <macrodef name="ant-macro">
        <attributes name="message"/>
        <sequential>
            <second-macro message="hi"/>
            <echo message="@{message}" />
        </sequential>
    </macrodef>