5.2 Creating Custom Scripts - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.8
5.2 Creating Custom Scripts
You can create your own Command scripts by running the create-script command from the root of your project. For example the following command will create a script calledsrc/main/scripts/hello-world.groovy
:grails create-script hello-world
In general Grails scripts should be used for scripting the Gradle based build system and code generation. Scripts cannot load application classes and in fact should not since Gradle is required to construct the application classpath.See below for an example script that prints 'Hello World':
description "Example description", "grails hello-world"println "Hello World"
description
method is used to define the output seen by grails help
and to aid users of the script. The following is a more complete example of providing a description taken from the generate-all
command:description( "Generates a controller that performs CRUD operations and the associated views" ) { usage "grails generate-all [DOMAIN CLASS]" flag name:'force', description:"Whether to overwrite existing files" argument name:'Domain Class', description:'The name of the domain class' }
grails generate-all MyClass --force