Clinton Bosch Clinton Bosch - 1 year ago 108
Java Question

Ant unless attribute not working?

I must be not understanding the

attribute properly. I have a properties file that has a property as follows:


And in my Ant build file I have the following piece

<echo message="Finance module enabled is ${}"/>
<echo message="Project module enabled is ${module.project.enabled}"/>
<javac srcdir="src" destdir="${classes}" debug="true">
<pathelement path="src"/>
<fileset dir="web/WEB-INF/lib" includes="*.jar"/>
<fileset dir="lib" includes="*.jar"/>
<fileset dir="${GWT.HOME}" includes="gwt-user.jar,gwt-servlet.jar"/>
<exclude name="bla/finance/*.java" unless="${}"/>
<exclude name="bla/project/*.java" unless="${module.project.enabled}"/>

When running my ant target the properties do seem to be read

[echo] Finance module enabled is true
[echo] Project module enabled is false

But when I look at the
directory I would have expected to see no classes in the project package and classes in the finance package but alas it seems to be excluding both packages?

Answer Source

For Ant 1.7 and prior, the if and unless attributes only check if a property is set. They don't actually check the value. You could in fact set it to anything, and that'll evaluate as true for if and false for unless. Likewise if you don't set it at all, you'll get false for if and true for unless.

In either case I'm not aware of the if and unless being available for <exclude>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download