在Ant中,我可以在一个目标的“depends”属性中使用一个属性吗?

5

我正在尝试使用Ant来完成以下操作:

<property name="test" value="123"/>
<target name="helloworld" depends="${test}"/>

但是我遇到了错误“目标${test}在项目中不存在”。

所以我猜我可以这样做?

2个回答

7
你可以使用AntCall任务来调用另一个任务中的任务。
<project>
    <target name="asdf">
        <property name="prop" value="qwer" />
        <antcall target="${prop}" />
    </target>

    <target name="qwer">
        <echo message="in qwer" />
    </target>
</project>

为了使两个任务相互依赖,您可以在依赖任务中设置一个参数,并在调用任务中进行检查。


3

不要使用 depends 属性,可以使用 if 属性来检查属性。有关详细信息,请参见手册

例如:

<target name="helloworld" if="test"/>

请注意,这仅检查属性是否设置(您可以使用unless来检查它是否未设置)。

另一种更复杂但功能更强大的方法是在依赖目标上使用嵌套条件:

<target name="helloworld" depends="myTarget.check" if="myTarget.run">
    ...
</target>

<target name="myTarget.check">
  <condition property="test">
    <and>
      <available file="foo.txt"/>
      <available file="bar.txt"/>
    </and>
</condition>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接