ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Heath, Graham" <>
Subject conditional global variables?
Date Tue, 28 Sep 2010 12:03:46 GMT
On Sep 26, 2010, at 8:23 AM, Marina wrote:

> Hello!
> In essence, I would like to know how to define a global property
> conditionally, and then have it available to all build files via <import>.

What I do is supply a -Dtarget=Debug or Release via the commandline which causes a
file to be built with useful things like build.number, build.time,, build.machine,
build.type and so on.

  <target name="init" depends="set_flags,announce,env.. ">
    <property file="build.number"/>
    <delete file=""/>
    <propertyfile comment="Build Information"
      <entry key="build.number"
      <entry key="build.version"
      <entry key="temp.dir"
      <entry key=""
      <entry key="build.user"

All my subservient build files just import this file <property file="${root.dir}/metadata/"/>
- oh and debug builds copy it into the dist directory too.. That way I have a chance to know
on a test machine where/when/who built the failing jar!

    |            |__ build.number
    |            |__
    |____Source jar1
    |            |__ build.xml
    |____Source jar2
    |            |__ build.xml


> Now the details:
> I have a build.common.xml file with all global properties and paths
> defined. I import it into my main build and component build files via
> <import>, and this makes everything that is defined in the common file
> available to all other build files.
> build.common.xml:
>            <property name="build.classes" value="${build}/classes"/>
>            ...
>      <path id="compile.classpath">
>            <pathelement location="${build}/classes"/>
>            <path refid="jdk.classpath"/>
>            <fileset dir="${lib}">
>                  <include name="**/*.jar"/>
>            </fileset>
> ...
> Then, I have a main build.xml that calls a few component build.xml via
> <ant file=...> call.
> If I <import> the build.common.xml into all my build files - I have
> all properties and paths available to all builds.
> It all works great, but now I want to have the build.classes property
> set conditionally, based on the build mode (dev vs. release). Ideally,
> I would like something similar to the C #ifdef macros:
> build.common.xml:
> if
>    mode='dev'
> then
>            <property name="build.classes"
> value="${build}/dev/classes"/> else
>            <property name="build.classes"
> value="${build}/release/classes"/>
> I can do the <if> logic if I define this property in the main build,
> for example, as part of some <init> task. But, it means that the
> property is not global anymore, and, which is more important, I cannot
> define my paths in the build.common.xml based on the value of this
> property. At least I could not figure out yet a way to do it...
> So, I was pondering over a few options:
> 1. define all properties like that and paths in the main build.xml and
> pass them as parameters to all component builds - very involved and inflexible...
> 2. define a target <init> in the build.common.xml that defines all
> those properties and paths - and make all builds call it (or depend on
> it) - again, very involved in terms of refactoring my existing builds, and inflexible.
> 3. any other way???
> If only I could just define that one global property conditionally! I
> feel like I'm missing some basic core concept here....
> Any pointers?
> Thanks!
> Marina

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