Gradle Grails Wrapper
This is a plugin for Gradle that builds Grails applications.
Using the plugin
The plugin isn't available at Maven Central, but is in a Maven-compatible repository on Github, so add this to your build.gradle script:buildscript {
repositories {
maven {
url 'http://burtbeckwith.github.io/gradle-grails-wrapper/m2/'
}
}
dependencies {
classpath 'com.burtbeckwith.gradle.grails:gradle-grails-wrapper:0.1'
}
}
and register a dependency for the plugin with
apply plugin: 'grails'
The plugin will auto-discover the version of Grails that you are using based on the version in build.properties and use it to execute Grails commands. If you are outside of a project (for example to run the create-app or create-plugin scripts) then the plugin looks for the GRAILS_HOME environment variable and uses that version of Grails. If that is not set, then it uses a default version.
There are a few configuration options that you can set in a grails block. The default values are
grails {
installBase = '/usr/local/javalib'
installPrefix = 'grails-'
defaultVersion = '2.0.4'
devVersion = '2.3.0.BUILD-SNAPSHOT'
devHome = System.env.HOME + '/workspace.grails/grails-core'
verbose = false
stacktrace = false
}
so for example if you use GVM you can change the directory where your Grails distributions are installed with
grails {
installBase = System.env.HOME + '/.gvm/grails'
installPrefix = ''
}
or to configure verbose output and full stacktraces, use
grails {
verbose = true
stacktrace = true
}
Using the plugin
The plugin finds all available Grails commands by looking in the scripts directory of your Grails install, and adds Gradle tasks for each one. The task name is the Grails command name prefixed with grails-, for example:
gradle grails-run-app
or
gradle grails-war
As with any Gradle project, to see all of the available commands run:
gradle tasks
Passing command arguments uses a different syntax than running regular Grails comands due to the Gradle command line parsing process. Also, when specifying arguments be sure to only execute one command since all arguments will be passed to all commands. There are two syntaxes supported, using -P or --project-prop, both using argN parameter names. For example running
gradle grails-create-domain-class -Parg0=com.test.Thing
gradle grails-generate-all --project-prop arg0=com.test.Thing
will create a domain class and generate static scaffolding for it.
To pass system parameters, use -P or --project-prop with dN argument names. So for example to build a war with a non-standard environment name "staging", use either
gradle grails-war -Pd0=grails.env=staging
or
gradle grails-war --project-prop d0=grails.env=staging
Included tasks
All Grails commands are registered as Gradle tasks with the grails- prefix as described above. They run with the -plain-output flag. If verbose is true in the grails configuration block, the --verbose flag is added, and if stacktrace is true the --stacktrace flag is added.
In addition, there is a plugin-init task which creates the grails-app/conf/hibernate, grails-app/conf/spring, test/integration, and test/unit directories to avoid warnings during testing and other scripts.
There is a clean task which depends on plugin-init and grails-clean, and deletes any log files in the base directory.
There is a test task that depends on clean and grails-test-app to ensure that tests run with newly compiled classes.
There is a package-plugin task which depends on test and grails-package-plugin to ensure that you run tests before building a plugin project ZIP file. It deletes any empty directories in the grails-app, lib, scripts, src, test, and web-app directories (including the directories themselves) since running test-app re-creates unnecessary empty directories.
Finally there is the post-package-cleanup task which deletes the empty directories described above; this is a standalone task so you can call it directly.
Build Scripts
You're free to add custom tasks to your build script, but an initial version can be as simple as
buildscript {
repositories {
maven {
url 'http://burtbeckwith.github.io/gradle-grails-wrapper/m2/'
}
}
dependencies {
classpath 'com.burtbeckwith.gradle.grails:gradle-grails-wrapper:0.1'
}
}
apply plugin: 'grails'
if by some usual coincidence you use the same install directories that I use.
A more realistic example using GVM would be
buildscript {
repositories {
maven {
url 'http://burtbeckwith.github.io/gradle-grails-wrapper/m2/'
}
}
dependencies {
classpath 'com.burtbeckwith.gradle.grails:gradle-grails-wrapper:0.1'
}
}
apply plugin: 'grails'
grails {
installBase = System.env.HOME + '/.gvm/grails'
installPrefix = ''
}
and for plugin projects you can make the package-plugin task the default with
defaultTasks 'package-plugin'
so you can run a full build with tests and packaging just by running
gradle