ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Pearson <>
Subject Doing both debug and release builds with same targets
Date Fri, 16 Nov 2001 00:42:54 GMT
This must be a relatively common task, so I present the Ant user commuity
with the following question: I am trying to write a build.xml file that can
build in either debug mode or release mode depending on which target is
invoked on the command line (or build them both). The difference between the
two builds will be the settings of the Optimization/Debug flags on the javac
tasks, and also the output directories for classes and other generated
files. My best solution has the following structure:

<?xml version='1.0' encoding='utf-8'?>
<project name="test" default="both" basedir=".">

        <target name="prepare">
                <echo message = "Preparing ${mode} directory." />

        <target name="compile-proj1" depends="prepare">
                <echo message = "compiling project 1 in ${mode} mode" />

        <target name="compile-proj2" depends="prepare">
                <echo message = "compiling project 2 in ${mode} mode" />

        <target name="build" depends="compile-proj1,compile-proj2" />

        <target name="debug-build">
                <property name="mode" value="debug" />
                <antcall target="build" />

        <target name="release-build">
                <property name="mode" value="release" />
                <antcall target="build" />

        <target name="both">
                <antcall target="debug-build" />
                <antcall target="release-build" />


When I run ant with the "both", the "debug-build" or the "release-build"
target, it does exactly what I want.  The problem with this Is that I can
only do the top-level build targets sucessfully.  If I am working on just
"project1", I'd like to be able to run "ant compile-proj1" and have it just
build that project (preferably in debug-mode).  However if I run ant that
way, the ${mode}does not get set, and I get the output:

     [echo] Preparing ${mode} directory.

     [echo] compiling project 1 in ${mode} mode

So what I tried to do was to insert the statement

            <property name="mode" value="debug" />

at the very beginning of the file (right after the <project> declaration).
My hope was that this would provide a "default" value for mode, and that
when I ran "release-build" or when "both" antcall'ed "release-build" the
property statement within that target would override the default setting.
Unfortunately, it didn't happen that way.  After adding the above property
statement, the release-build target started using ${mode}="debug".

Can I have my cake and eat it too? Is there a way to set the default value
of ${mode} to be "debug" and have it set to "release" only when the
release-build target is run?



Alan Pearson


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message