如何使用不同的参数几次运行自定义任务?

时间:2011-11-23 04:41:10

标签: ant

我正在尝试执行目标“MyTarget”并收到错误:“不支持的元素回显”。也许Macrodef不是做这项工作的方式。有没有其他方法可以将任务传递给具有不同参数的另一个目标/ macrodef?

<macrodef name="dotask">
    <attribute name="platform" description="" />
    <attribute name="config" description="" />
    <element name="task2" optional="true" />
    <sequential>
        <task2 />
    </sequential>
</macrodef>

<macrodef name="buildsuite2">
    <element name="task" optional="true" />
    <sequential>
        <dotask platform="win32" config="debug">
            <task />
        </dotask>   
        <dotask platform="win32" config="release">
            <task />
        </dotask>
    </sequential>
</macrodef>

    <target name="MyTarget">
        <buildsuite2>
            <task>
                <echo>${platform} ${config}</echo>
            </task>
        </buildsuite2>
    </target>

1 个答案:

答案 0 :(得分:1)

  

如何使用不同的参数几次运行自定义任务?

是的,你可以在antcall任务的帮助下完成。

样本:

<target name="method_impl">
    <echo message="${firstParam}"/>
    <echo message="${secondParam}"/>
</target>

<target name="test_calling_twice">
    <echo message="First time call"/>
    <antcall target="method_impl">
        <param name="firstParam" value="fP1"/>
        <param name="secondParam" value="sP1"/>
    </antcall>

    <echo message="Second time call"/>
    <antcall target="method_impl">
        <param name="firstParam" value="fP2"/>
        <param name="secondParam" value="sP2"/>
    </antcall>
</target>

输出将是:

  

第一次打电话   fP1
  sP1
  第二次打电话   fP2
  sP2