You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Amshoff <ch...@fja.com> on 2000/09/07 11:09:03 UTC

Order of property tasks relevant?

Hi.

I just started with Ant (Release 1.1, Win NT) and am wondering
about the way properties are resolved.

For example: given the following buildfile

<?xml version="1.0"?>
<project name="JJSys" default="main" basedir=".">
  <target name="main" depends="A">
    <echo message="var is '${var}'" />
  </target>
  <target name="A" depends="B">
    <echo message="var is '${var}'" />
  </target>
  <target name="B">
    <property name="var" value="some value"/>
    <echo message="var is '${var}'" />
  </target>
</project>

and building the default target 'main' I would expect the
property 'var' to be set in all targets 'main', 'A' and 'B'.
In fact, the output is

Buildfile: test.xml

B:
var is 'some value'

A:
var is '${var}'

main:
var is '${var}'

BUILD SUCCESSFUL

It seems to make a difference where the definition of the
property (and target 'B') is noted in the buildfile, because
if I swap the definition of targets 'B' and 'A' in the code,
'var' is resolved in 'A', too.
Thus, the properties are resolved only at locations in the
buildfile which are below their definition task? This is IMHO
not documented in the user manual.
Is it a feature? Or a bug?

Thanks for any help on this.
Christoph.


Re: Order of property tasks relevant?

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "A" == Amshoff  <ch...@fja.com> writes:

 A> Hi.  I just started with Ant (Release 1.1, Win NT) and am
 A> wondering about the way properties are resolved.

Yes, they are confusing to put it as friendly as possible.

Basically, don't put <property> inside any targets, move them at the
top of your project and you won't get confused by the following facts:

(1) <property> is executed even if it is nested into a target that is
not part of the dependency tree.

(2) <property> is executed at parser time, not at runtime.

(3) <property>s are executed in the order the parser finds them (the
physical order in the file).

(4) ${} replacement happens at parser time - if you use ${} before you
define the property (again physically) like you do in your example,
the expansion cannot work as the property hasn't been defined yet.

(5) <property> will never overwrite the value of a property set
before.

All these things are true for Ant 1.1 up to current CVS. Some things
(I'm still not sure if all points of this list) are going to change in
the future and before we release the next version.

Stefan