How to execute the same target twice with different properties?

igormukhin
igormukhin used Ask the Experts™
on
Hello,

i wonder how to make ant execute the same target more than once with dirrent properties.

The next script doesn't work as I expected:

    <target name="test1">
          <property name="prop1" value="11111" />
          <antcall target="test2" />
        <property name="prop1" value="22222" />
        <antcall target="test2" />
    </target>

    <target name="test2">
          <echo>${prop1}</echo>
    </target>

The output is:

test1:
test2:
     [echo] 11111
test2:
     [echo] 11111

But I expect:

test1:
test2:
     [echo] 11111
test2:
     [echo] 22222


What do i do wrong and what is the right way to do it?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
Try defining 'prop1' as a global property
Java Architect
Commented:
Pass a param to antcall:
<target name="test1">
  <antcall target="test2">
    <param name="prop1" value="11111"/>
  </antcall>
  <antcall target="test2">
    <param name="prop1" value="22222"/>
  </antcall>
</target>
 
<target name="test2">
  <echo message="prop1 =${prop1}"/>
</target>

Open in new window

Top Expert 2016

Commented:
You'd be better with this approach:
    <target name="test1">
	<antcall target="test2">
	    <param name="prop1" value="11111" />
	</antcall>
	<antcall target="test2">
	    <param name="prop1" value="22222" />
	</antcall>
    </target>
 
    <target name="test2">
	<echo>${prop1}</echo>
    </target>

Open in new window

Top Expert 2016

Commented:
Sorry Bart_Cr - didn't see that

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial