Agile Zone is brought to you in partnership with:

Meera has posted 70 posts at DZone. You can read more from them at their website. View Full User Profile

Ant or Gant?

09.23.2008
| 42386 views |
  • submit to reddit

If you have written or even modified Ant build files, you will know that it contains one project element, which in turn contains  a name,the default target and the base directory.  

Code Listing 4:

<project name="GantSamples" basedir="." default="compile">

So for example, sayHello target in Ant would look something like this:

<target name="sayHello" description="Saying Hello">
<echo message="Hello Javalobby"/>
</target>

Lets create the sayHello target, and also see how to set it as the default target in Gant as well.

A Gant target has a name and a description:

Code Listing 5:

target ( target-name : target-description ) {
groovy code sequence
}

The above sayHello target in Gant would translate as shown below:

target(sayHello:"Saying hello"){
Ant.echo(message:"Hello Javalobby")
}

Now, open a command window and type gant at the root of the project where the build.gant file exists. You should be able to see a output like:

meera-subbaraos-macbook-9:CodeMetricsProject meerasubbarao$ gant
Target default does not exist.
 

Gant is complaining that we haven't set a Default target. Lets see how to do the same:

Default target: Within Ant, you define the default target from within the project element as seen in Listing 4. The default target is the target called if no target is specified from the command line. There however is no project tag within Gant. There are two ways of specifying the default target as shown below:


1. You simply create a target whose name is default.

target ( 'default' , 'The default target.' ) { aTarget ( )

2. or even simply:

setDefaultTarget ( aTarget )

In order to get our sayHello target working, we need to add one of the above scripts to our build.gant file.

Code Listing 6:

setDefaultTarget(sayHello)
or
target ("default": "The default target." ) {
sayHello ( )
}

Complete listing of build.gant:

target(sayHello:"Saying hello"){
Ant.echo(message:"Hello Javalobby")
}

/*
target ("default": "The default target." ) {
sayHello ( )
}
*/

setDefaultTarget(sayHello)

And you should be able to see:

meera-subbaraos-macbook-9:CodeMetricsProject meerasubbarao$ gant
     [echo] Hello Javalobby
meera-subbaraos-macbook-9:CodeMetricsProject meerasubbarao$

That was easy! If you have build files and it is becoming unmanageable by your team, there is a tool out there which can convert your Ant scripts to Gant scripts as well. I haven't used it, but you can try it here.

In this part of the series, we learned when to move over from Ant to Gant, downloaded and installed Gant, and finally wrote a simple gant build file. In the next part of this series, we will see Gant in Action within a simple Java project.

And as always, keep us posted here if you are encountering any problems getting started with Gant. Stay tuned.

Published at DZone with permission of its author, Meera Subbarao.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Mike P(Okidoky) replied on Mon, 2008/09/29 - 10:54pm in response to: phil swenson

I want to be able to write (or use someone else's) template scripts, and use it to create buildable projects from it. I want to be able to open a text editor, type in the name of the project, the names of the java files, jar library files, and the name of the script that it needs to process it.

That way, I can keep upgrading the scripts without having to touch each project.

Serge Bureau replied on Tue, 2008/09/30 - 7:13am in response to: Mike P(Okidoky)

[quote=okidoky]

I want to be able to write (or use someone else's) template scripts, and use it to create buildable projects from it. I want to be able to open a text editor, type in the name of the project, the names of the java files, jar library files, and the name of the script that it needs to process it.

That way, I can keep upgrading the scripts without having to touch each project.

[/quote]

 

Why should I need any XML/XSL for that ?

phil swenson replied on Tue, 2008/09/30 - 9:03am in response to: Serge Bureau

"Why should I need any XML/XSL for that ?"

 You don't.  That's what is so great about using a real language, you can make the build do whatever you want.

Kenneth Wheeler replied on Fri, 2009/11/20 - 6:12am

I agree with what you said about Ant or Gant?. Get Tall Ant or Gant?. How to Grow Taller Naturally Ant or Gant?. Growing Taller Secrets

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.