ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject RE: conditional compilation 2
Date Fri, 21 Jun 2002 14:21:56 GMT
Note that <fail if="property" /> is only available in Ant 1.5!

Also, if you get tired of typing properties on the Ant command line, you can
use targets to set them:

<target name="linux">
  <property name="LINUX" value="1" />

<target name="windows">
  <property name="WINDOWS" value="1" />

So 'ant -DLINUX=1 distrib' becomes 'ant linux distrib'. If you have more
than one property to set, it's very useful. You could also do:

<target name="deploy.linux"
        depends="linux, deploy" />

And call 'ant linux.deploy'.

And finally, when you also have more than one platform dependent property
(but not dependent on the platform you're currently running which can be
inferred automatically, using <osfamily> or <condition>&<os> for example),
it's a good idea to put each set of platform specific properties in a
separate properties file.

In Dmitry's case, I'd define two properties files and, and do something like:

<target name="init">
  <property name="build-properties"
            location="${targetos}" />
  <available property="build-properties.exists"
             file="${build-properties}" />
  <fail message="Unknown targetos = ${targetos}"
        unless="build-properties.exists" />
  <property file="${build-properties}" />

And then call 'ant -Dtargetos=linux distrib'.

This solves the problem neatly, and is expendable to any number of targetos
without modifying the build.xml.

Hope this helps. --DD

PS: if <property file=""> had two new attributes similar to <junit> to tell
it to fail when the file is not found or property name to set in such a
case, it would be reduced to <property file="" failureProperty="notfound" />
and <fail message="" if="notfound" />

PS2: Using <fileset> and <pathconvert>, it's also possible to give a listing
of the available valid 'targetos' values. I'll leave that as an exercise to
the reader.

-----Original Message-----
From: Marc Gemis [] 
Sent: Friday, June 21, 2002 5:14 AM
To: Dmitry Trunikov;
Subject: Re: conditional compilation 2

On 6/21/02 12:05 PM, "Dmitry Trunikov" <> wrote:

>   Hi ALL!
> I checked mail archive but didn't find answer for my question.
> My problem is following. I have java application that is built by ant.
> Application is OS depended therefore I pass target  OS as build
> property: ant -DLINUX=1 or ant -DWINDOWS=1. I would like to add to
> build.xml some code that can does validation of input properties for
> mutual exclusion,  i.e. command for build: ant -DLINUX=1 -DWINDOWS=1 is
> not valid.

<target name="init">
    <condition property="linux_and_windows">
            <isset property="LINUX" />
                <!-- you could also use <equals arg1="LINUX" arg2="1"> -->
            <isset property="WINDOWS" />
    <fail message="Either LINUX or WINDOWS, not both" if="linux_and_windows"


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

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

View raw message