passing properties defined inside antcall target back to calling target

One approach is to write out a property to a temp file using "echo file= ...." or PropertyFile task. Then read the property back in where required. Kludge but works.


Ant tasks are all about stuff goes in, side effect happens. So trying to program in terms of functions (stuff goes in, stuff comes out) is going to be messy.

That said what you can do is generate a property name per invocation and store the result value in that property. You would need to pass in a indentifier so you do not end up trying to create copies of the same property. Something like this:

<target name="default">
  <property name="key" value="world"/>
  <antcall target="doSomethingElse">
     <param name="param1" value="${key}"/>
  </antcall>
  <echo>${result-${key}}</echo>
</target>
<target name="doSomethingElse">
   <property name="hello-${param1}" value="it works?"/>
</target>

But I believe the more typical approach -instead of antcalls- is to use macros. http://ant.apache.org/manual/Tasks/macrodef.html


Use antcallback from the ant-contrib jar instead of antcall

<target name="testCallback">
    <antcallback target="capitalize2" return="myKey">
    </antcallback>
    <echo>a = ${myKey}</echo>
</target>

<target name="capitalize2">
    <property name="myKey" value="it works"/> 
</target>

Output:

testCallback:

capitalize2:
     [echo] a = it works

BUILD SUCCESSFUL

Tags:

Ant