An Ant Modular Build Environment for Enterprise Applications
Subject:   Location independance
Date:   2005-09-16 05:48:29
From:   LesHazlewood
Response to: Location independance

I agree with you. At the time I made the sample application, I was wondering about the best way to do this.

The problem with a hierarchical build is that each module must know the hierarchy's root directory to maintain references to other modules and submodules. This is key to enabling a build (via 'ant') at any level in the hierarchy.

So, the easiest way (and the way I used in the sample application) was to just specify the root directory as an absolute path. As you have noted, this requires developers to change that property to work on their system.

Ideally, it would be really nice to just do an RCS checkout and run the build, without having to change anything.

So, I use a little technique to make sure that doesn't happen -

Each module and submodule defines the root directory via a relative path before importing the parent's build file.
Because you define it before the import, that value won't be overridden by any parent definitions (remember, ant keeps the first value it finds).

This is accomplished via the following (for a module):

<?xml version="1.0"?>

<project name="someName" default="dist">

<property name="root.base.dir" value="../">

<import file="../build.xml"/>


And for a submodule:

<?xml version="1.0"?>

<project name="someName" default="dist">

<property name="root.base.dir" value="../../">

<import file="../build.xml"/>


After making these simple respective adjustments in each module and submodule, you can do a fresh checkout and not have to modify any settings for paths. Much nicer...



Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Location independance
    2006-08-02 11:25:42  RodMcDonald [View]

    Great article, good ideas.
    1. I found that the global-init target (in the top level build.xml) may specify the following

    <property name="root.base.dir" value="./"/>

    This has so far worked for me.

    2. For template targets I needed to add inheritAll="false" so that ant invoking ant in another directory would set up the correct root.base.dir.

    <target name="template" depends="prepare">

    <ant target="${target}" dir="server" inheritAll="false"/>
    <ant target="${target}" dir="client" inheritAll="false"/>