我正在尝试使用Ant来完成以下操作:
<property name="test" value="123"/>
<target name="helloworld" depends="${test}"/>
但是我遇到了错误“目标${test}在项目中不存在”。
所以我猜我可以这样做?
我正在尝试使用Ant来完成以下操作:
<property name="test" value="123"/>
<target name="helloworld" depends="${test}"/>
但是我遇到了错误“目标${test}在项目中不存在”。
所以我猜我可以这样做?
<project>
<target name="asdf">
<property name="prop" value="qwer" />
<antcall target="${prop}" />
</target>
<target name="qwer">
<echo message="in qwer" />
</target>
</project>
为了使两个任务相互依赖,您可以在依赖任务中设置一个参数,并在调用任务中进行检查。
不要使用 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>