How to Use Macrodef?
Lets Assume This Is My Code. buildJar Is My Macrodef. How to Invoke Macrodef "Buildjar" Based on Some Condition? for Example, Above Code Can Be: 1 1 Answer Ant...
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>
1 Answer
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>