Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass ant target to multiple build.xml files in subdirectories

Tags:

build

ant

I have a project with multiple modules, each in its own directory. Each module has its own ant build file (build.xml)

In the root directory I've set up a general build file that calls the build file of each module in the right order.

<?xml version="1.0"?>
<project name="bridgedb" default="all" basedir=".">
  <target name="all">
    <ant dir="corelib"/>
    <ant dir="tools"/>
    <ant dir="makeGdb"/>
    <ant dir="cytoscape-plugin"/>
  </target>
</project>

Now each module also has a "clean" target, so I add these lines:

 <target name="clean">
    <ant dir="corelib" target="clean"/>
    <ant dir="tools" target="clean"/>
    <ant dir="makeGdb" target="clean"/>
    <ant dir="cytoscape-plugin" target="clean"/>
  </target>

And there are more targets like that. Is there a way to rewrite the build file to avoid this duplication? I've looked for a built-in property that contains the active target, but I couldn't find it.

like image 363
amarillion Avatar asked May 04 '09 10:05

amarillion


2 Answers

Why not use antcall to call a target that references all your subdirs, and parameterise the target to be called. e.g.

 <antcall target="doStuffToSubdirs">
    <!-- let's clean -->
    <param name="param1" value="clean"/>
  </antcall>

and then:

<target name="doStuffToSubdirs">
   <ant dir="corelib" target="${param1}"/>
   <ant dir="tools" target="${param1}"/>
    ...etc
</target>

so this allows you to parameterise the calls to your subdirs. If you add a new subdir, you only have to add that subdir to the 'doStuffToSubdirs' target (I would rename that as well!)

like image 149
Brian Agnew Avatar answered Sep 25 '22 05:09

Brian Agnew


Put one clean target in your commonbuild.xml and in the child files just import your parent build.xml

<import file="${parent.dir}/commonbuild.xml" />

Now you will be able to call the clean target in your child builds. You can also override this target by creating a clean target in any of your child builds.

like image 21
Nuno Furtado Avatar answered Sep 24 '22 05:09

Nuno Furtado