You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Kief Morris <ki...@bitBull.com> on 2000/10/16 15:30:51 UTC

setting properties

I've just installed and started trying out Ant 1.1. One thing that doesn't
work the way I expect is setting properties. I would like to have different
targets set the same property to different values, so it can be referred to
in subsequent targets. An examle is building code in a different directory
depending on whether I'm building for debug or distribution.

However, ant seems to set the property using the first <property> tag in
the build.xml file, even if it's within a target that is not executed. For
example:

<project name="P1" default="Target2">

	<target name="Target1">
		<property name="foo" value="T1"/>
		<echo message="Target1, foo = ${foo}"/>
	</target>
	
	<target name="Target2">
		<property name="foo" value="T2"/>
		<echo message="Target2, foo = ${foo}"/>
	</target>
	
</project>


Running this produces:
------------------------------------------------------------
Buildfile: build.xml

Target2:
Target2, foo = T1

BUILD SUCCESSFUL

Total time: 0 seconds
------------------------------------------------------------

Is this the intended behavior? If so, are there any examples of build files
which build alternative versions of a project with minimal redundant xml
code? I've checked out the Tomcat build file, but it only builds one version.

Apologies if this is in the FAQ, but I've been getting internal server 
errors on
the faq-o-matic on jakarta.apache.org for the past few days.

Thanks,
Kief


            The Wildest party on the Net is on!
                     http://www.Wild5.com



RE: setting properties

Posted by Kief Morris <ki...@bitBull.com>.
Conor MacNeill typed the following on 00:37 17/10/00 +1100
 >> However, ant seems to set the property using the first <property> tag in
 >> the build.xml file, even if it's within a target that is not executed. For
 >> example:
 >Yep, that is how ant 1.1 works - properties are set at parse time. This has
 >been changed in ant 1.2

Great, I've tried out today's build and it works. Thanks Conor and Stefan for
the lightning quick response. I'm really pleased with Ant, it's exactly what
I need.

\kief


            The Wildest party on the Net is on!
                     http://www.Wild5.com



Re: setting properties

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "KM" == Kief Morris <ki...@bitBull.com> writes:

 KM> However, ant seems to set the property using the first <property>
 KM> tag in the build.xml file, even if it's within a target that is
 KM> not executed.

This has been true for Ant 1.1 but has changed for Ant 1.2 (which is
currently getting very close to its release date). What you try to do
should work with Ant 1.2 - as long as you set a property only once in
your process, i.e. the other <property> tags are really not executed.

Stefan

RE: setting properties

Posted by Conor MacNeill <co...@m64.com>.
Kief,

> -----Original Message-----
> From: Kief Morris [mailto:kief@bitBull.com]
>
> I've just installed and started trying out Ant 1.1. One thing that doesn't
> work the way I expect is setting properties. I would like to have
> different
> targets set the same property to different values, so it can be
> referred to
> in subsequent targets. An examle is building code in a different directory
> depending on whether I'm building for debug or distribution.
>
> However, ant seems to set the property using the first <property> tag in
> the build.xml file, even if it's within a target that is not executed. For
> example:
>

Yep, that is how ant 1.1 works - properties are set at parse time. This has
been changed in ant 1.2, which will be released shortly, so that properties
scoped within a targetr are only set when that target is executed. Note,
however, that properties are still immutable.

Conor