ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <qazw...@gmail.com>
Subject Re: conditional global variables?
Date Mon, 27 Sep 2010 00:28:17 GMT
There are several ways this can be done:

One is to use multiple tasks:

<target name="compile">
    <antcall target="compile.dev"/>
    <antcall target="compile.release"/>
</target>

<target name=compile.dev"
    if="mode.dev">
    <property name="build.classes" value="${build}/dev/classes"/>
</target>

<target name="compile.release"
    unless="mode.dev">
    <property name="build.classes" value="${build}/release/classes"/>
</target>

In the example you gave, you could simply set the property "type" to
either "dev" or "release":

    <property name="build.classes" value="${build}/${type}/classes"/>

You can also use separate XML property files:

    <xmlproperty file="build.${type}.xml" keeproot="false"/>

Or, you can use the antcontrib library which includes a conditional
"if" statement. If you do this, I would put the ant-contrib.jar file
in a directory called "antlib" in the root of your project and use the
following <typedef>:

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
        <pathelement location="${basedir}/antlib/ant-contrib.jar"/>
    </classpath>

This way, ant will work without having to specifically install the
ant-contrib.jar file.

You can find Ant-Contrib at: http://ant-contrib.sourceforge.net

The <if> task looks like this:

<if>
    <isset property="type">
    <then>
        <property name="build.classes" value="${build}/dev/classes"/>
    </then>
    <else>
        <property name="build.classes" value="${build}/release/classes"/>
    </else>
</if>

-- 
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message