如何使用macrodef?

时间:2014-09-19 06:35:11

标签: ant antlr

让我们假设这是我的代码。 buildJar是我的macrodef。

    <target name="build"> 
     <buildJar build.dir="module1"/>
     <buildJar build.dir="module2"/>
     </target>

如何调用macrodef&#34; buildJar&#34;基于某些条件?例如,上面的代码可以是:

    <target name="build">
        <if module="module1" >
            <buildJar build.dir="module1"/>
        </if>
        <if module="module2" >
           <buildJar build.dir="module2"/>
        </if>
    </target>

1 个答案:

答案 0 :(得分:0)

Ant支持if and unless attributes。这些可以使用available task

与目录检查结合使用
<project name="demo" default="build" xmlns:if="ant:if">

  <macrodef name="greeting">
    <attribute name="name"/>
    <sequential>
      <echo message="found @{name}"/>
    </sequential>
  </macrodef>

  <available property="found.module1" file="module1"/>
  <available property="found.module2" file="module2"/>

  <target name="build">
    <greeting name="module1" if:true="${found.module1}"/>
    <greeting name="module2" if:true="${found.module2}"/>
  </target>

</project>
相关问题