我有一个乱七八糟的版本。最后,目标最多执行15次。大多数目标都被执行了十几次。这是因为构建和目标被分成10个独立的构建文件(build.xml、build-base.xml、compile.xml等)。
在许多构建文件中,在构建文件中的所有目标之外,您一开始就有<property>任务。这些函数通常在调用任何目标之前先执行。
这是我的build.xml文件:
<import file="build-base.xml"/>
[...]
<target name="compile-base">
<antcall target="setup-tmpj"/>
<ant antfile="compile.xml" target="compile-base"/>
[...]
</target>下面是compile.xml文件:
<import file="build-base.xml"/>
<property name="target" value="1.5"/>
<available file="target/gensrc/com" property=gensrc.exists"/>
[...]
<target name="buildAndCompileCodeGen" unless=gensrc.exists">
<blah blah blah/>
</target>
<target name="compile-base" depends="buildAndCompileCodeGen">
<blah blah blah/>
</target>我执行以下代码:
$ ant -f build.xml compile-base这将调用compile.xml文件中的目标compile-base。这取决于compile.xml文件中的目标buildAndCompileCodeGen。但是,只有在未设置属性gensrc.exists时,才会执行目标buildAndCompileCodeGen。
compile.xml文件中有一个<available>任务,它将设置gensrc.exists属性,但此任务位于compile.xml中所有目标的外部。是否调用过<available>任务,从而设置了gensrc.exist?
发布于 2012-09-14 04:40:59
好吧,我知道怎么回事了.
是的,当我通过<ant>任务调用compile.xml文件中的compile-base目标时,在我调用的目标执行之前,所有不在目标下的任务都会被执行。这意味着,如果代码已经存在,则会调用buildAndCompileCodeGen目标,但不会执行。
我所做的是将所有的构建文件合并到一个大文件中,并摆脱了所有的<ant>和<antcall>任务。我将<available>任务放在组合的build.xml文件中。
在最初的情况下,我首先执行一个clean,然后在compile.xml文件中调用compile-base。此时,将运行<available>任务。因为我做了清理,所以文件不存在,属性gencode.exists没有设置,buildAndCompileCodeGen目标将会运行。
当我组合所有内容时,将运行<available>任务,并设置gencode.exists属性。然后,当我执行clean时,我会删除生成的代码。但是,因为已经设置了gencode.exists,所以buildAndCompileCodeGen目标仍然不会执行。
应该做的是:
<target name="compile-base"
depends="buildAndCompileCodeGen">
<echo>Executing compile-base</echo>
</target>
<target name="buildAndCompileCodeGen"
depends="test.if.gencode.exists"
unless="gencode.exists">
<echo>Executiing buildAndCompileCodeGen</echo>
</target>
<target name="test.if.gencode.exists">
<available file="${basedir}/target/gensrc/com"
property="gencode.exists"/>
</target>在本例中,我调用了compile-base。它将调用buildAndCompileCodeGen。这将首先调用test.if.gencode.exists。即使已经设置了属性gencode.exists,也会执行此操作。在Ant查看if或unless参数之前,依赖子句在目标上运行。这样,在准备执行buildAndCompileCodeGen目标之前,我不会设置gencode.exists。现在,可用任务将在I执行清理后运行。
https://stackoverflow.com/questions/12413199
复制相似问题