我有一个像这样的蚂蚁文件:
<project name="test" basedir="." default="build">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/data/build/scripts/ant-contrib-0.6.jar" />
</classpath>
</taskdef>
<property name="target" value="/tmp/target.file" />
<target name="build" depends="checkDone,fullBuild,noBuild" >
<echo message="Build process completed for ${target}"/>
</target>
<target name="checkDone" >
<available file="${target}" property="done"/>
</target>
<target name="noBuild" if="done" >
<echo message="Build process skipped, ${target} already done" />
</target>
<target name="fullBuild" depends="step1,step2" unless="done" >
<echo message="Build process executed for ${target}" />
</target>
<target name="step1" >
<echo message="Executing step1" />
</target>
<target name="step2" >
<echo message="Executing step2" />
</target>
</project>
TL; DR:如果文件在那里,我想执行“noBuild”,如果不是,我想执行由step1和step2组成的“fullBuild”。
问题是:如果文件已经存在,则跳过“fullBuild”,但step1和step2不是......:这是日志:
Apache Ant version 1.6.5 compiled on June 2 2005
Buildfile: /data/build/scripts/test.ant
Detected Java version: 1.5 in: /soft/ibm/WebSphere/ProcServer/java/jre
Detected OS: Linux
parsing buildfile /data/build/scripts/test.ant with URI = file:///data/build/scripts/test.ant
Project base dir set to: /data/build/scripts
Build sequence for target(s) `build' is [checkDone, step1, step2, fullBuild, noBuild, build]
Complete build sequence is [checkDone, step1, step2, fullBuild, noBuild, build, ]
checkDone:
[available] Found: /tmp/target.file
step1:
[echo] Executing step1
step2:
[echo] Executing step2
fullBuild:
Skipped because property 'done' set.
noBuild:
[echo] Build process skipped, /tmp/target.file already done
build:
[echo] Build process completed for /tmp/target.file
BUILD SUCCESSFUL
那么,我错过了什么?或者我应该在所有目标中真正拥有“除非”条款吗?
答案 0 :(得分:1)
这是一个常见的蚂蚁问题。来自目标的if / unless属性不适用于依赖链 因此,请参阅ant manual:
重要说明:if和unless属性仅启用或禁用 它们所附着的目标。他们不控制是否 目标条件目标依赖于执行。事实上, 他们甚至没有得到评估,直到目标即将到来 已执行,其所有前任已经执行。
所以你必须使用除属性也用于stepX目标:
<target name="step1" unless="done">
<target name="step2" unless="done">