## 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:

    grails create-script compile-sources

Will create a script called `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:

    target(default:"The default target is the one that gets executed by Grails") {
    	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")
    }

As demonstrated in the script above, there is an implicit `ant` variable that allows access to the Apache Ant API.

> In previous versions of Grails (1.0.3 and below), the variable was `Ant`, i.e. with a capital first letter.

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 the `setDefaultTarget()` method:

    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")

This allows you to call the default target directly from other scripts if you wish. Also, although we have put the call to `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.