3

我在各种目录中有一堆子项目。我想将它们指定为一个列表,然后对于给定的目标,我想逐个遍历每个目标并调用 subant。

我有类似的东西:

<target name="run">
    <subant target="run" failonerror="true" verbose="true">
        <fileset dir="${projectA}" includes="build.xml"/>
    </subant>
    <subant target="run" failonerror="true" verbose="true">
        <fileset dir="${projectB}" includes="build.xml"/>
    </subant>
</target>

但是我必须为每个项目和每个目标集指定一个单独的子行。我要做的就是创建一个作为子项目列表的属性,并以某种方式使用它。它应该很简单,但是....

4

1 回答 1

5

您可以定义一个宏来执行此操作:

<macrodef name="iterate-projects">
    <attribute name="target" />
    <sequential>
        <subant target="@{target}">
            <filelist dir="${src_dir}">
              <file name="projectA/build.xml"/>
              <file name="projectB/build.xml"/>
              <file name="projectC/build.xml"/>
            </filelist>
        </subant>
    </sequential>
</macrodef>

然后从另一个任何任务中,您可以按顺序在所有构建上调用目标,例如:

<target name="clean" description="Clean all projects">
   <iterate-projects target="clean"/>
</target>
于 2009-04-21T21:22:51.217 回答