0

Lets assume this is my code. buildJar is my macrodef.

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

How to invoke macrodef "buildJar" based on some condition? For example, above code can be:

    <target name="build">
        <if module="module1" >
            <buildJar build.dir="module1"/>
        </if>
        <if module="module2" >
           <buildJar build.dir="module2"/>
        </if>
    </target>
user3492304
  • 153
  • 2
  • 4
  • 11

1 Answers1

0

Ant supports if and unless attributes. These can be combined with a directory check using the 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>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185