ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject Re: Conditional compilation
Date Thu, 13 Jun 2002 12:21:22 GMT

   From: "Erik Hatcher" <>
   To: "Ant Users List" <>
   Subject: Re: Conditional compilation

   You're bound to get a flood of replies to this:

   <property name="build.debug" value="true"/>
   <javac debug="${build.debug}">

   then run with: ant -Dbuild.debug=false to turn it off.

Thanks, Erik!

I have two follow-up questions; they are both about useful things I
used to accomplish with command-line flags when I used make, but I
can't figure out how to do it with ant.

With make, to conditionally include source files in the distribution
jar, I would do something like:

  SOURCE_TO_JAR = ${SourceFiles}

The ${SOURCE_TO_JAR} would be one of the arguments to the jar command
in the Jar target; it would be an empty string unless WITH_SOURCE was
set via

  make -WITH_SOURCE=1

Now with ant I would like to have a command-line flag
-Dwithsource=true that similarly causes source code to be included in
the distribution jar.  The problem is that I can't figure out where to
make that set variable act, since the obvious place, namely the
fileset data type, doesn't accept the if/unless attributes.

The best I can come up with in this case is something like this:

  <target name="jar" depends="init,compile">
    <jar jarfile="MyProject-${DSTAMP}.jar" manifest="Manifest">
      <!-- basedir="${build}" -->
      <fileset dir="${build}"/>
      <fileset dir="${sourcedir}"

and run with

  % ant -Dwithsource='**/*.java'

To my surprise, this actually seems to work without major mishaps, but
this way of setting the withsource flag is difficult to remember, and
it is not suitable for cases where the fileset specification for the
source files to include is more complicated.  The approach I describe
above with make as far cleaner and easier to use.  Is there a way to
do this with ant?

The second question relates to my other questions so far.  It has to
do with making a command-line flag imply another.  Again, in the case
of make, if I wanted the flag DEBUG to imply the WITH_SOURCE flag, I
would simply add this to my makefile:

  ifdef DEBUG

  # etc., etc.

How can I do a similar thing with ant?

Again, thanks for your help!


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message