问题描述
为了简单解释,这里是一个例子:
To explain it briefly, here is an example:
在 build.xml 中,导入了 local-db.xml.在 local-db.xml 中,有一个名为warmup"的目标,它使用任务调用第三个文件的一个目标——local-gr.xml.
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.
所有公共属性和类路径定义都在 build.xml 中导入和设置.
All the common properties and classpath defs are imported and set in build.xml.
在 project.properties 中:
in project.properties:
dest-dir=./destination
在 build.xml 中:
in build.xml:
<path id="gr-classpath"> ... </path>
<import file="local-db.xml" />
在 local-db.xml 中:
in local-db.xml:
<ant antfile="local-gr.xml" target="deploy" inheritAll="true" inheritRefs="true" />
在 local-gr.xml 中,有两个这样的目标:
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>
问题来了:
属性${dest-dir}和路径gr-classpath"可以在deploy"中使用,因为我设置了inheritAll和inheritRefs,但不能在deploy-single"中直接使用.当目标被 foreach 调用时,继承"不会?
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?
在 的帮助下,我设法将 ${dest-dir} 传递给deploy-single",但我没有找到任何方法将类路径引用gr-classpath"传递给deploy-single".
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".
我为解决这个问题所做的是在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?
推荐答案
ant-contrib foreach
任务 默认情况下不会传播对其目标的所有属性和引用.但它确实具有 inheritall
和 inheritrefs
属性,您可以使用它们来实现这一点.
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"
/>
这篇关于[ANT]属性和类路径引用继承在“foreach"中被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!