4.1 Creating Gant Scripts - Reference Documentation
Authors: Andres Almiray
Version: 1.2.0
4.1 Creating Gant Scripts
You can create your own Gant scripts by running the create-script command from the root of your project. For example the following command:griffon create-script compile-sources
scripts/CompileSources.groovy
. A Gant script itself is similar to a regular Groovy script except that it supports the concept of "targets" and dependencies between them:scripts/CompileSources.groovy
target(default:"The default target is the one that gets executed by Griffon") { depends(clean, compile) } target(clean:"Clean out things") { ant.delete(dir:"output") } target(compile:"Compile some sources") { ant.mkdir(dir:"mkdir") ant.javac(srcdir:"src/main", destdir:"output") }
ant
variable that allows access to the Apache Ant API.You can also "depend" on other targets using the depends
method demonstrated in the default
target above.The default target
In the example above, we specified a target with the explicit name "default". This is one way of defining the default target for a script. An alternative approach is to use thesetDefaultTarget()
method:scripts/CompileSources.groovy
target("clean-compile": "Performs a clean compilation on the app's source files.") { depends(clean, compile) } target(clean:"Clean out things") { ant.delete(dir:"output") } target(compile:"Compile some sources") { ant.mkdir(dir:"mkdir") ant.javac(srcdir:"src/java", destdir:"output") }setDefaultTarget("clean-compile")
setDefaultTarget()
at the end of the script in this example, it can go anywhere as long as it comes after the target it refers to ("clean-compile" in this case).Which approach is better? To be honest, you can use whichever you prefer - there don't seem to be any major advantages in either case. One thing we would say is that if you want to allow other scripts to call your "default" target, you should move it into a shared script that doesn't have a default target at all. We'll talk some more about this in the next section.