views:

152

answers:

1

I have a bunch of sub projects in various directories. I want to specify them as a list, then for a given target I want to go through each one, one-by-one and call subant.

I've got something like:

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

But I would have to specify a separate subant line for each project and each target set. All I want to do is create a property that is a list of sub-projects, and use that somehow. It should be simple, yet ....

+3  A: 

You can define a macro to do this:

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

Then from another any task, you can call a target on all of the builds in sequence, e.g.:

<target name="clean" description="Clean all projects">
   <iterate-projects target="clean"/>
</target>
Chris Thornhill
Nice, that worked well when I set src_dir to .. (my buildAll project is at the same level as the others).
Paul W Homer