You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Jérôme Lacoste <je...@smartcardsystem.com> on 2001/06/11 17:12:18 UTC

better reuse/extension of build files - How about an OO approach for build file definition?

I've been using Ant for some time now, but I am not sure whether it can
easily achieve what I would like to do with it.

My idea is to enforce a common structure in all my projects with minimum
duplication of the build file. All my projects have the same targets, almost
always identical, but sometimes with little changes.
	!! I would like to avoid duplicating my 'master' build file and modify it
slightly in all projects !!


The best is to give an example:
I have a build file which contains a 'prepare' target.
This target creates the necessary directories for the build. In 90 % of my
projects it creates a 'classes' directory, a 'dist' directory, etc..
One of my projects would like to have a specific directory. My clean target
would takes care of removing this specific directory.
I would like to reuse the same generic build file without having to recreate
a new one just because this 'prepare' target is different.


I didn't find a way in Ant to have the same flexibility as one finds in the
OO way, specifically with inheritance and overriding.

If there was an OO approach to define the build file, this would be easy:

<!-- hypothetic simple example -->

<project name="base" ....>
  <target name="build" depends="prepare,compile">
  </target>
  <target name="prepare">
    <mkdir dir="classes" />
    <mkdir dir="docs" />
  </target>
  <target name="compile">
    ....
  </target>
</project>

<project name="projectX" ....  reusedproject="base">
  <!-- overriden & reuse "two" from "base" project -->
  <target name="prepare">
     <super/> <!-- reuse the 'prepare' target of the 'base' project -->
     <mkdir dir="temp" />
  </target>
</project>


nb: I didn't reuse Java keywords by purpose. Proposed implementation is
purely hypothetical.

--> Question: It is possible to achieve the same degree of flexibility and
reusability with Ant? If so, how are you doing this reuse in your projects?

--> If not, could we add a requirement for Ant2 to enforce the reusability
and flexibility?
This could of course perhaps be implemented as shown above or in a non-OO
way.

--> Another idea: I think it would help a lot if there was some kind of
small repository with a selection of - complete and complex - build
examples.

Jerome