ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig Longman <>
Subject global properties
Date Thu, 20 Sep 2001 07:31:22 GMT

i have a situation where i want one and only one of a set of three
targets executed.  i've been playing around with setting properties
values inside each target, and the other targets would first check to
see if that property has been set, and if so then exit out.  i started
running into problems where properties set in the sub-targets would not
be visible outside of that target.  i upgraded to 1.4 but still found
the same behaviour.

it seems that this is behaviour by design, but i'm not sure what to do
now.  because 'child' targets cannot set/modify parent properties (even
for themselves), how is this sort of thing handled?  i must be missing a
tag or an attr somewhere, but i can't find it in the docs, nor searchign
the archives.  here is a very basic build.xml i have:

<project name="test" default="default">

<target name="default">
 <property name="use.target1" value="true"/>
 <property name="use.target2" value="true"/>
 <antcall target="target1"/>
 <antcall target="target2"/>
 <echo message="${prop2}"/>

<target name="target1" depends="check" if="use.target1">
 <property name="prop1" value="test1"/>
 <property name="prop2" value="test2"/>

<target name="target1" depends="check" if="use.target2">
 <property name="prop1" value="test1"/>
 <property name="prop2" value="test2"/>

<target name="check" if="prop1">
 <fail message="prop1 already set"/>


so, now the problem.  the default target sets the use.target1 and
use.target2 props, so both the target1 and target2 will _try_ to run. 
what is supposed to happen here is that the prop1 gets set in the
target1 target, so when the target2 runs, the check target will fail. 
problem #1 is that prop1 isn't being recognized in the default or
target2 targets.  which also messes me up for the prop2 property, which
is supposed to be a real property that is used in later targets.

in the example, for normal conditions, only one of the use.targetX props
would be set.  i'm just trying to catch the error cases gracefully in
the build file.

below is the output from the sample build.xml file.  another interesting
thing that confused me a bit; the output shows that the default target
was called, followed by check+target1 and then check+target2, then the
[echo] is printed out.  but, there is no indication that the current
target is now the default target again.  perhaps something that
indicated when a target returned from an antcall?  this problem doesn't
show itself with the 'depends', because those are executed BEFORE the
current target, i think this only affects the antcall task.

Buildfile: build.xml





     [echo] ${prop2}


any assistance would be greatly appreciated.



View raw message