我有一个混乱的构建。最后,目标最多执行 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-base中的目标compile.xml。这取决于文件buildAndCompileCodeGen中的目标compile.xml。但是,buildAndCompileCodeGen只有在未设置属性时才会执行目标gensrc.exists。
该compile.xml文件中有一个<available>将设置gensrc.exists属性的任务,但该任务位于compile.xml. 是否曾经调用过该<available>任务,所以gensrc.exist设置好了?