You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Jean-Noel Gadreau <jn...@activcard.com> on 2000/06/10 20:22:11 UTC

Defining tasks in several build.xml files

Hi all.

I am using now using to build several on the projects I am working on and it
is great ! I have a question on how to share some tasks across projects.

In fact, I have several components that all share the same pieces of
'build.xml' (to checkout their dependencies from CVS for instance, or to
compile all the java files as the structure of all the project is similar).

So, I would like to know if there is a way with Ant to define a task that
can be "included" in another 'build.xml', so that you can have a kind of
repository of common tasks that you can include.

If such a thing does not exist, do you have suggestions on what you (all Ant
users) would like so that I can see if I can add it.

Best regards,
Jean-Noel Gadreau

Re: Defining tasks in several build.xml files

Posted by "Pierre, Sebastian" <sp...@Rational.Com>.
> So, I would like to know if there is a way with Ant to define a task
> that can be "included" in another 'build.xml', so that you can have a
> kind of repository of common tasks that you can include.
> 
> If such a thing does not exist, do you have suggestions on what you
> (all Ant users) would like so that I can see if I can add it.

Hi !

I guess I'm answering a little bit lately to your message, and somebody
may have already answered your question.

My suggestion is to use entities, which are typically an XML thing that
allows inclusion of file (a little bit like #define and #include in C).

For example if you use the following task in each of your project:

  | <taskdef name="myTask" classname="org.myname.MyClass"/>

You can embed it into an entity :

  | <!ENTITY mytask
  |  "<<taskdef name="myTask" classname="org.myname.MyClass"/>"
  | >

But to embed this entity into your 'build.xml' document you've got to
add a DOCTYPE section :

  | <?xml version="1.0" ?>
  |
  | <!DOCTYPE project
  | [
  | <!ENTITY mytask
  |	"<<taskdef name="myTask" classname="org.myname.MyClass"/>"
  | >
  | ]>

And if you want to share this entity between your project, put its
declaration into an xml 'chunk' file :

  +Full listing of the /tmp/taskdef.xch file
  | <!ENTITY mytask
  |	"<<taskdef name="myTask" classname="org.myname.MyClass"/>"

  +Beginning of your project file
  | <?xml version="1.0" ?>
  |
  | <!DOCTYPE project
  | [
  |   <!ENTITY % taskdefs SYSTEM "/tmp/taskdef.xch">
  |   %taskdef;
  | >
  | ]>
  | 
  | <project name="myProject">
  |   &mytask;
  |  ...

Notice that entities prefixes by a % are used ONLY inside a DOCTYPE
section, and the entities prefixed by an & are used outside (generally).

Hope this helps!

Bye,
Seb.