在包含的ant文件中访问项目前缀

时间:2014-07-29 07:50:19

标签: ant

是否可以在包含的ant文件中访问“as”前缀 (即访问include task)中指定的“as”属性值

文件includes.xml:

<project name="myproject">
  <include file="included.xml" as="nested" />
</project>

file included.xml:

<project>
  <echo message="I am included into ${ant.project.name} as ${SomePropertyIAskAbout}" />
</project>

所需的输出:“我作为嵌套包含在myproject中”

1 个答案:

答案 0 :(得分:0)

<include>执行包含的构建文件,就好像在包含构建文件中一样。让两个文件引用自定义属性都可以解决问题。

including.xml

<project name="myproject">
    <property name="including-as-attribute" value="nested" />
    <include file="included.xml" as="${including-as-attribute}" />
</project>

included.xml

<project>
    <fail unless="including-as-attribute"/>
    <echo message="I am included into ${ant.project.name} as ${including-as-attribute}" />
</project>

ant -f including.xml

的输出
 [echo] I am included into myproject as nested