Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant:antcall构建文件中设置的属性会发生什么变化?_Ant_Build - Fatal编程技术网

Ant:antcall构建文件中设置的属性会发生什么变化?

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">

我的身材真是一团糟。最后,目标执行多达15次。大多数目标执行了十几次。这是因为构建和目标分为10个独立的构建文件(
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
。现在,可用任务将在我执行清理后运行