如何通过使用antcall传递不同的参数值来调用相同的目标?

时间:2014-09-18 06:10:37

标签: ant antlr

如何通过向参数传递不同的值来调用相同的目标? 我想用antcall调用目标。 基于一些falg我想通过使用param将不同的值传递给参数来调用目标。

1 个答案:

答案 0 :(得分:2)

不要使用antcall,更好地使用macrodef(在Ant 1.6中引入)代替!!
我不会详细介绍,只需在网上搜索“antcall vs. macrodef”和类似的内容。
另见Writing Better Ant Scripts: Techniques, Patterns and Antipatterns
一些片段:

<project xmlns:if="ant:if">

 <macrodef name="foobar">
  <attribute name="foo"/>
  <attribute name="verbose"/>
  <sequential>
   <echo>@{foo}</echo>
   <echoproperties prefix="ant" if:true="@{verbose}"/>
  </sequential>
 </macrodef>

 <!-- use foobar macrodef with different parameters (attribute values) -->
 <foobar verbose="yes" foo="1. yada,yada"/>
 <foobar verbose="no" foo="2. blabla.."/>

</project>

输出:

[echo] 1. yada,yada
[echoproperties] #Ant properties
[echoproperties] #Thu Sep 18 09:31:05 CEST 2014
[echoproperties] ant.core.lib=C\:\\ant194\\lib\\ant.jar
[echoproperties] ant.file=C\:\\area51\\ant\\tryme.xml
[echoproperties] ant.home=C\:\\ant194
[echoproperties] ant.java.version=1.7
[echoproperties] ant.library.dir=C\:\\ant194\\lib
[echoproperties] ant.version=Apache Ant(TM) version 1.9.4 compiled on April 29 2014
[echo] 2. blabla..