Always Read the Documentation

Recently, Chris and I were working on an Ant build file for one of our projects.

The following is from an Ant Tutorial

The target element is used as a wrapper for a sequences of actions. A target has a name, so that it can be referenced from elsewhere, either externally from the command line, or internally via the depends keyword, or through a direct call.
Source

We had a target that we wanted to execute only if a particular condition had been set. Searching the online ant manual I found that the target element had an if attribute. Natuaraly, I thought that setting this element to either true or false would cause this target to either run or not. We set our target as follows:

<target name="background_process" if="run.background.task">

We set the run.background.task to true in a property file on one machine and false on another. We then used Cruise Control to kick off a build on both machines. The target ran successfully on both boxes, even though we set the property on one of the boxes to false. What happened?

It turns out that the if attribute allows a target to run if an attribute is set. The target will run if the attribute is given anyvalue at all. This is not a boolean expression! In our case the solution was to set the property on one box and ignore it completely on the other.

The moral of this: always read the documentation and do not make any assumptions.

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply