Ant Tasks, such as <if>, belongs to ant-contrib.jar. So in order to use them in maven-antrun-plugin, you have to add this dependency explicitly in the pom.xml.
<!-- Properties -->
<properties>
<greeting>true</greeting>
</properties>
<!-- Build Configuration -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>20020829</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>initialize</id>
<phase>initialize</phase>
<configuration>
<tasks>
<!-- add the ant tasks from ant-contrib -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<!-- show greeting if ${greeting} is set to true-->
<if>
<equals arg1="${greeting}" arg2="true" />
<then>
<echo>Hello World</echo>
</then>
</if>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Please remember to add the tasks definition of ant-contrib.jar using the <taskdef> inside the <tasks> node.
Run mvn initialize, the console will echo the greeting message only if the ${greeting} property is set to true.
Done =)

Thanks this has been really handy!
LikeLike
You are welcome =)
LikeLike
This works only for older versions of Ant because it is using antcontrib.properties. Newer versions use antlib.xml instead.
LikeLike
Thanks for your note. =)
LikeLike