2011-11-23 33 views
1

我想执行目标“MyTarget”,并得到一个错误:“不支持的元素回声”。也许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> 

回答

0
​​

是的,你可以用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> 

输出将是:

First time call
fP1
sP1
Second time call
fP2
sP2

+0

我有一组PARAMS将重新使用了相当数量的自定义任务。做你的建议可能会解决这个问题,但我必须为每个参数组写一个antcall。如果我添加一个新的参数集,我必须为每个自定义任务添加一个新的antcall。 –

+0

@Chau你可以使用[macrodef](http://ant.apache.org/manual/Tasks/macrodef.html)和antcall来分解公共代码。 – sudocode

相关问题