先来看下macrodef的说明

This defines a new task using a <sequential> nested task as a template. Nested elements <attribute> and <element> are used to specify attributes and elements of the new task. These get substituted into the <sequential> task when the new task is run.

下面是ant doc的一个example
<macrodef name="test">  这里是macrodef的定义,定义了name属性
<attribute name="one"/> 参数定义,可以在macrodef外部调用
<attribute name="two" default="@{one}"/> 内部参数
<sequential>
实际执行的内容在sequential里
<echo>one=@{one} two=@{two}</echo>
</sequential>
</macrodef>

<test one="test"/> 外部调用

需要注意的是:
1、在整个build文件里macrodef是和target平级的。
2、macrodef可以调用其他macrodef,不可以调用target;target可以调用macrodef,也可以调用其他target
3、macrodef嵌套的时候,参数名称必须不同
比如上面的macrodef test,定义了one的参数
如果定义另外一个macrodef test2 也有一个参数,最好不要再叫one了,不然容易出现混乱


相关文章:

  • 2021-07-07
  • 2022-01-16
  • 2021-08-02
  • 2021-08-25
  • 2022-12-23
  • 2021-09-25
  • 2021-10-28
  • 2021-10-04
猜你喜欢
  • 2022-01-23
  • 2021-10-05
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案