You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Richard Grey <ri...@haamdhani.com> on 2004/08/31 19:19:15 UTC

Overriding a property and subsequently derived properties

I have two targets A and B in a single build.xml file. Both targets 
utilise a single property X which is set differently (via an environment
 variable).
 
Normally, I would use a command line to set the environment variable and
 call target A, then reset the environment variable and then call target
 B.
 
All well and good, but I wish to automate this manual process. I've 
tried using a batch file with the above, but the batch file finishes 
completely after the first target completes.
 
So I thought I'd get Ant to do it for me from another target C. I've 
tried using <antcall> and overriding property X, but my problem is that 
despite property Y being derived from X, property Y never changes when 
property X is overridden.
 
Follow ?! Is this expected ? Can anybody please help, or suggest what I 
could/should do to achieve what I want, ie property Y also changing ?
 
Obviously, this is a simplified test case, and just overrding property Y
 isn't ideal. In the real world, I have a multitude of other properties 
derived from the "changing" original.
 
Thanks
 
--
 
<?xml version="1.0" encoding="UTF-8"?>
 
<project basedir=".">
 
        <property environment="env"/>
 
        <property name="X" value="${env.MY_VARIABLE}" />
        <property name="Y" value="${X}/Y" />
        
        <target name="A">
               <echo message="X is ${X}"/>
               <echo message="Y is ${Y}"/>
        </target>
 
        <target name="B">
               <echo message="X is ${X}"/>
               <echo message="Y is ${Y}"/>
        </target>
 
 
        <target name="C">
               <ant antfile="temp.xml" target="A">
                       <property name="X" value="A" />
               </ant>
               <ant antfile="temp.xml" target="B">
                       <property name="X" value="B" />
               </ant>
        </target>
        
</project>
 
--
 
> set MY_VARIABLE=Z
> ant -f temp.xml C
Buildfile: temp.xml
 
C:
 
A:
     [echo] X is A
     [echo] Y is Z/Y
 
B:
     [echo] X is B
     [echo] Y is Z/Y
 
BUILD SUCCESSFUL

Total time: 0 seconds