Pass ant target to multiple build.xml files in subdirectories
Solution 1
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!)
Solution 2
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.
T9b
I do a lot of java and web development. I'm also an linux / open source enthusiast, and dabble in game programming in my (scarce) free time (Check out: www.helixsoft.nl)
Updated on July 11, 2022Comments
-
T9b almost 2 years
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.
-
T9b about 15 yearsIf I understand this correctly, that assumes that the "clean" target does exactly the same thing in each subdirectory. But that is not the case, especially not for other targets that I may wish to call in the same way.
-
T9b about 15 yearsalthough it should be <antcall target="..." and not <antcall name="..."
-
T9b about 15 yearsnp, this is a useful trick too that I may use some other day :)
-
Brian Agnew about 15 yearsI'll correct that now. Thx for the heads up (I confess I didn't test that :-)
-
Tazzy531 almost 15 yearshttp://www.exubero.com/ant/dependencies.html <-- I just implemented this in my build environment. Makes everything very clean and simple. I have one main build-common.xml and if I need to override the main, I just do it in the build.xml in the submodules.