[ANT]Property and Classpathref inherit broken in “foreach”

天大地大妈咪最大 提交于 2019-12-24 09:49:43

问题


To explain it briefly, here is an example:

In build.xml, local-db.xml is imported. And in local-db.xml, there is a target named "warmup" which calls one target of the third file -- local-gr.xml using task.

All the common properties and classpath defs are imported and set in build.xml.

in project.properties:

dest-dir=./destination

in build.xml:

<path id="gr-classpath"> ... </path>
<import file="local-db.xml" />

in local-db.xml:

<ant antfile="local-gr.xml" target="deploy" inheritAll="true" inheritRefs="true" />

In local-gr.xml, there are two targets like this:

<target name="deploy">
    <tar ....../>
    <foreach list="${list1}" delimiter="," parallel="true" trim="true" param="item" target="deploy-single" />
</target>

<target name="deploy-single">
    something using property ${dest-dir} and path "gr-classpath"
</target>

Now here is the problem:

The property ${dest-dir} and path "gr-classpath" can be used in "deploy" because I set inheritAll and inheritRefs, but it can't be used directly in "deploy-single". "inherit" doesn't when the target is called by foreach?

I managed to pass ${dest-dir} to "deploy-single" with the help of the , but I didn't find any way to pass the classpathref "gr-classpath" to "deploy-single".

What I did to work around it was to claim the again in "deploy-single", but I don't like it at all.

Why this happens? What can I do to make it more elegant?


回答1:


The ant-contrib foreach task doesn't by default propagate all properties and references to it's target. But it does have inheritall and inheritrefs attributes that you can use to make that happen.

<foreach list="${list1}" delimiter="," parallel="true" trim="true"
         param="item" target="deploy-single"
         inheritall="true" inheritrefs="true"
/>


来源:https://stackoverflow.com/questions/6759750/antproperty-and-classpathref-inherit-broken-in-foreach

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!