Ant:antcall构建文件中设置的属性会发生什么变化?
我的身材真是一团糟。最后,目标执行多达15次。大多数目标执行了十几次。这是因为构建和目标分为10个独立的构建文件(Ant:antcall构建文件中设置的属性会发生什么变化?,ant,build,Ant,Build,我的身材真是一团糟。最后,目标执行多达15次。大多数目标执行了十几次。这是因为构建和目标分为10个独立的构建文件(build.xml,build base.xml,compile.xml,等等) 在许多构建文件中,在构建文件的所有目标之外,您在开始时都有任务。这些通常在调用任何目标之前首先执行 这是我的build.xml文件: <import file="build-base.xml"/> [...] <target name="compile-base">
build.xml
,build base.xml
,compile.xml
,等等)
在许多构建文件中,在构建文件的所有目标之外,您在开始时都有任务。这些通常在调用任何目标之前首先执行
这是我的build.xml
文件:
<import file="build-base.xml"/>
[...]
<target name="compile-base">
<antcall target="setup-tmpj"/>
<ant antfile="compile.xml" target="compile-base"/>
[...]
</target>
<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
文件中有一个
任务,该任务将设置gensrc.exists
属性,但该任务位于compile.xml
中的所有目标之外。有没有调用过
任务,从而设置了gensrc.exist
是的,当我通过
任务调用compile.xml
文件中的compile base
目标时,在执行我调用的目标之前,将执行目标下的所有任务。这意味着,如果代码已经存在,则调用但不执行buildAndCompileCodeGen
目标
我所做的是将所有构建文件合并到一个大文件中,并去掉所有的
和
任务。我已经将
任务放在组合的build.xml
文件中
在最初的情况下,我会首先执行清理
,然后在compile.xml
文件中调用compilebase
。此时,
任务将运行。由于我进行了清理,因此文件不存在,未设置属性gencode.exists
,并且将运行buildAndCompileCodeGen
目标
当我组合所有内容时,
任务将运行,设置gencode.exists
属性。然后,当我进行清理时,我会删除生成的代码。但是,buildAndCompileCodeGen
目标仍然不会执行,因为已经设置了gencode.exists
应该做的是:
<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>
执行编译基
执行buildAndCompileCodeGen
在本例中,我调用compilebase
。这将调用buildAndCompileCodeGen
。它将首先调用test.if.gencode.exists
。即使已设置属性gencode.exists
,也会执行此操作。在Ant查看if
或除非参数之前,依赖子句在目标上运行。这样,在准备执行buildAndCompileCodeGen
目标之前,我不会设置gencode.exists
。现在,可用的任务将在我进行清理后运行。好的,我知道发生了什么
是的,当我通过
任务调用compile.xml
文件中的compile base
目标时,在执行我调用的目标之前,将执行目标下的所有任务。这意味着,如果代码已经存在,则调用但不执行buildAndCompileCodeGen
目标
我所做的是将所有构建文件合并到一个大文件中,并去掉所有的
和
任务。我已经将
任务放在组合的build.xml
文件中
在最初的情况下,我会首先执行清理
,然后在compile.xml
文件中调用compilebase
。此时,
任务将运行。由于我进行了清理,因此文件不存在,未设置属性gencode.exists
,并且将运行buildAndCompileCodeGen
目标
当我组合所有内容时,
任务将运行,设置gencode.exists
属性。然后,当我进行清理时,我会删除生成的代码。但是,buildAndCompileCodeGen
目标仍然不会执行,因为已经设置了gencode.exists
应该做的是:
<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>
执行编译基
执行buildAndCompileCodeGen
在本例中,我调用compilebase
。这将调用buildAndCompileCodeGen
。它将首先调用test.if.gencode.exists
。即使已设置属性gencode.exists
,也会执行此操作。在Ant查看if
或除非参数之前,依赖子句在目标上运行。这样,在准备执行buildAndCompileCodeGen
目标之前,我不会设置gencode.exists
。现在,可用任务将在我执行清理后运行