+ There are actually several answers to this question.
+ If you have only one set and one unset property to test,
+ you can put both an if
and an unless
+ attribute into the target. The target will act as if they
+ are "anded" together.
+ If you are using a version of Ant 1.3 or earlier, the
+ way to work with all other cases is to chain targets together
+ to determine the specific state you wish to test for.
+ To see how this works, assume you have three properties,
+ prop1
, prop2
, and prop3
.
+ You want to test that prop1
and prop2
+ are set, but that prop3
is not. If the condition
+ holds true you want to echo "yes".
+ Here is the implementation in Ant 1.3 and earlier:
+
+ Note that <antcall>
tasks do not pass
+ property changes back up to the environment they were called
+ from.
+ Starting with Ant 1.4, you can use the
+ <condition>
task.
+
+ This version takes advantage of two things:
+
+ - If a property
a
has not been set,
+ ${a}
will evaluate to ${a}
.
+
+ - To get a literal
$
in Ant, you have to
+ escape it with another $
- this will also break
+ the special treatment of the sequence ${
.
+
+ This is neither readable, nor easy to understand, therefore
+ post-1.4.1 Ant introduces the <isset>
element
+ to the <condition>
task.
+ Here is the previous example done using
+ <isset>
:
+
+ The last option is to use a scripting language to set the
+ properties. This can be particularly handy when you need much
+ better control than the simple conditions shown here, but of
+ course comes with the overhead of adding JAR files to support
+ the language, to say nothing of the added maintenance in requiring
+ two languages to implement a single system.
+
+