具有嵌套任务的 Ant 属性集继承
我有一组嵌套的 Ant 构建文件,我需要控制每个“子”任务继承哪些属性。我试图将它们定义为属性集(以保持代码可管理),但与属性不同,它们不会被子任务继承。
下面的示例演示了这个问题,foo.*
被复制到中间项目,但没有复制到底部项目。如果我明确定义要继承的每个属性,例如 bar.*
,它们也会被底层项目继承。
有没有什么方法可以让一组属性一直继承下去,就像单个属性一样?在不重写子流程的情况下,我还可以尝试其他方法吗?
[top.xml]
<?xml version="1.0"?>
<project name="test-top">
<property name="foo.1" value="1"/>
<property name="foo.2" value="2"/>
<property name="bar.1" value="1"/>
<property name="bar.2" value="2"/>
<ant antfile="middle.xml" inheritall="false">
<propertyset>
<propertyref prefix="foo."/>
</propertyset>
<property name="bar.1" value="${bar.1}"/>
<property name="bar.2" value="${bar.2}"/>
</ant>
</project>
[middle.xml]
<?xml version="1.0"?>
<project name="test-middle">
<echo>foo ${foo.1} ${foo.2}</echo>
<echo>bar ${bar.1} ${bar.2}</echo>
<ant antfile="bottom.xml" inheritall="false"/>
</project>
[bottom.xml]
<?xml version="1.0"?>
<project name="test-bottom">
<echo>foo ${foo.1} ${foo.2}</echo>
<echo>bar ${bar.1} ${bar.2}</echo>
</project>
[ant -f top.xml 的输出]
[echo] foo 1 2
[echo] bar 1 2
[echo] foo ${foo.1} ${foo.2}
[echo] bar 1 2
I have a set of nested Ant build files, and I need to control which properties are inherited by each "sub" task. I'm trying to define these as propertysets (to keep the code manageable) but these are not inherited by subtasks, unlike properties.
The example below demonstrates the problem, foo.*
get copied into the middle project but not to the bottom project. If I define each property to be inherited explicitly, like bar.*
, they get inherited by the bottom project too.
Is there any way to get a group of properties to inherit all the way down, in the same way individual properties do? Without rewriting the sub-processes, is there something else I could try?
[top.xml]
<?xml version="1.0"?>
<project name="test-top">
<property name="foo.1" value="1"/>
<property name="foo.2" value="2"/>
<property name="bar.1" value="1"/>
<property name="bar.2" value="2"/>
<ant antfile="middle.xml" inheritall="false">
<propertyset>
<propertyref prefix="foo."/>
</propertyset>
<property name="bar.1" value="${bar.1}"/>
<property name="bar.2" value="${bar.2}"/>
</ant>
</project>
[middle.xml]
<?xml version="1.0"?>
<project name="test-middle">
<echo>foo ${foo.1} ${foo.2}</echo>
<echo>bar ${bar.1} ${bar.2}</echo>
<ant antfile="bottom.xml" inheritall="false"/>
</project>
[bottom.xml]
<?xml version="1.0"?>
<project name="test-bottom">
<echo>foo ${foo.1} ${foo.2}</echo>
<echo>bar ${bar.1} ${bar.2}</echo>
</project>
[OUTPUT OF ant -f top.xml]
[echo] foo 1 2
[echo] bar 1 2
[echo] foo ${foo.1} ${foo.2}
[echo] bar 1 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为亚历山大的解决方案很接近。不过,这个怎么样,不需要对 middle.xml 或 Bottom.xml 进行任何更改。
这个想法是使用
echoproperties
任务将属性集“展开”到各个属性,然后在ant
任务调用中使用它。在调用 middle.xml 之前,使用如下所示编写属性集:
然后调用 middle.xml:
提供给 ant 任务的属性 按照你说的一路向下继承,所以你只需要改变top.xml:
I think Alexander's solution is close. How about this though, doesn't need any change in middle.xml or bottom.xml.
The idea is to use the
echoproperties
task to 'unroll' the propertyset to individual properties, then to use that in theant
task call.Before calling middle.xml, write the property set out using something like this:
Then make the call to middle.xml:
Properties supplied to the ant task inherit all the way down as you say, so you only need to change top.xml:
在 top.xml 中,您可以使用
任务创建具有可继承属性的文件。然后,您可以在每个子模块中使用
加载此文件。In top.xml you can create a file with inheritable properties using
<propertyfile>
task.Then you can load this file with
<property file="..."/>
in each of your submodules.