Search code examples
ant

passing properties defined inside antcall target back to calling target


I'm rather new to Ant but I have experienced it's quite good pattern to create generic ant targets which are to be called with antcall task with varying parameters.

My example is compile target, which compiles multiple systems using complex build command which is a bit different for each system. By using pattern described above it's possible not to create copy paste code for that compile command.

My problem here is, that I'm not aware of any way to pass return value (for example the return value of compiler) back to target which called the antcall task. So is my approach pathological and it's simply not possible to return value from antcall task or do you know any workaround?

Thanks,


Solution

  • 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