Alan
Alan

Reputation: 1198

Passing multiple targets to a subant

I have an Android project built with Ant using some standard targets (debug, release, install, clean, etc). I've found that I can run multiple targets with a command like:

ant clean debug

which in this case would run "clean" followed by "debug" build on the project. This works fine.

I also have another project built with Ant on which my first master project depends. I'm trying to automatically build the subproject in the prebuild step. So far I have this:

<target name="-pre-build">        
    <subant target="${ant.project.invoked-targets}" failonerror="true">
        <fileset dir="../other_project" includes="build.xml" />
    </subant>

    <!-- (additional steps here) -->
</target>

This works for one target (e.g. ant debug) but when I run multiple targets (e.g. ant clean debug) I get the following error:

Target "clean,debug" does not exist in the project "com.foo.other_project"

Clearly invoked-targets is a comma-separated list when I really want to re-run subant for each of the targest. Does anyone know how to achieve this? Is there a way to pass a list of targets to subant, or perhaps iterate through the list and run subant once per target?

Thanks!

Upvotes: 1

Views: 540

Answers (1)

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77971

The documentation describes how to specify multiple targets:

You can specify multiple targets using nested "target" elements instead of using the "target" attribute. These will be executed as if Ant had been invoked with a single target whose dependencies are the targets so specified, in the order specified.

An example is also provided:

<subant failonerror="false">
    <fileset dir="." includes="**/build.xml" excludes="build.xml"/>
    <target name="clean"/>
    <target name="build"/>
</subant>

Upvotes: 1

Related Questions