This post was started the day after a Geek Night, it was a very, very cool Night…
With every topic I wanted to talk more about it and I felt we didn’t have enough time to get all the buzz out but one thing that struck me was that not many people seem to have heard of Gant. This is a real shame as I have recently converted and therefore have all the zeal of the convert. This zeal leads me to try and convert those who have not seen the light (yet).
What is Gant? It is a Groovy wrapper around Ant tasks. Groovy comes with an Ant Wrapper so what’s the great shakes you might ask? When Gant handles all the target dependencies for the project. It is essentially the missing part of the puzzle that gives you all the Ant functionality and a lot more. Gant adds some methods to the base Groovy shell execution environment that allows you to say that a task A depends on task B.
Enough chat though let’s get on with some examples. Download the standalone gant installation and then invoke the gant script (for your environment) in a new empty directory. It will give you a moan about not being able to find a build.gant file. So let’s create one now.
My first gant file is on Pastebin, cut and paste into your build.gant (or retype it to really get the benefit).
Now when you call gant you should see Target A and Target B printed out in the order of their dependencies. Type gant b and just Target B should be printed.
To be honest this really is the core of Gant so it may seem trivial but it’s important to understand. After all if you have ever taken a crack at this Kata you will know that dependency resolution isn’t trivial.
So what should we take away from this small example? Well I think it is important to note that it is Groovy syntax, the attribute assignment in target is standard but note that we don’t need to quote the property on the left. The string is like the description attribute in standard Ant tasks.
The println call is not mapping onto Ant’s echo it is the Groovy println so all the normal stuff to do with GStrings (like interpolation) applies here. Similarly the block attached to the target is a normal closure.
Dependencies are listed by calling depends, why isn’t that in the target declaration like in Ant? Well because you can create a dependency at any point in the closure. That means you can dynamically define the dependency graph. Which when you think about it, is kind of mental.
I did not want to have a huge post so the next one is going to be about using that dynamic definition to DRY out my Gant file.