开发者

Ant var and property scope

开发者 https://www.devze.com 2022-12-18 19:22 出处:网络
I have a main build script that calls various targets.One of these targets needs to sto开发者_JS百科re a value and another target needs to display it.Obviously this is not working so I think it may be

I have a main build script that calls various targets. One of these targets needs to sto开发者_JS百科re a value and another target needs to display it. Obviously this is not working so I think it may be related to scope. I've tried var, property, and declaring the property outside of target1. Since var seems to be mutable, it looks like I need to use it instead, but each time my output is empty.

Main script

<antcall target="target1"/>
<antcall target="display"/>

In target1:

<var name="myVar" value="${anotherVar}"/>

In display:

<echo>${myVar}</echo>


Do you really need to use <antcall>? Can you use target dependencies instead?

As you suspect, using <antcall> essentially creates a new scope.


antcall will start the ant target in a new project and will not affect the main project in any way. Try runtarget from antcontrib to run the targets in the same project.


You can call multiple targets with one antcall element. These targets will then share a single project instance including the properties defined. To do this specify the targets as nested elements like this:

<antcall>
  <target name="target1"/>
  <target name="display"/>
</antcall>


Another option I found was the antcallback, and it appears to work. This limits what is returned to just a particular list of values, which seems inherently safer than opening up the scope of the whole target (as it sets, creates, modifies many var and properties).

<antcallback target="target1" return="myVar"/>
<antcall target="display"/>

I think all of these are valid solutions, it just depends on what level you want to change the variable scope at.


<antcall target="display">
   <param name="param1" value="anything" />
</antcall>

put the above code in your target1. I am sure you will be able to access your param1 in display now.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号