5.4 Building with Gradle - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.9
Table of Contents
5.4 Building with Gradle
Grails 3.1 uses the Gradle Build System for build related tasks such as compilation, runnings tests and producing binary distrubutions of your project. It is recommended to use Gradle 2.2 or above with Grails 3.1.The build is defined by thebuild.gradle file which specifies the version of your project, the dependencies of the project and the repositories where to find those dependencies (amongst other things).When you invoke the grails command the version of Gradle that ships with Grails 3.1 (currently 2.9) is invoked by the grails process via the Gradle Tooling API:# Equivalent to 'gradle classes' $ grails compile
gradle command and use your own local version of Gradle, however you will need Gradle 2.2 or above to work with Grails 3.0:$ gradle assemble
5.4.1 Defining Dependencies with Gradle
Dependencies for your project are defined in thedependencies block. In general you can follow the Gradle documentation on dependency management to understand how to configure additional dependencies.The default dependencies for the "web" profile can be seen below:dependencies {
compile 'org.springframework.boot:spring-boot-starter-logging'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile 'org.springframework.boot:spring-boot-autoconfigure'
compile 'org.springframework.boot:spring-boot-starter-tomcat'
compile 'org.grails:grails-dependencies'
compile 'org.grails:grails-web-boot' compile 'org.grails.plugins:hibernate'
compile 'org.grails.plugins:cache'
compile 'org.hibernate:hibernate-ehcache' runtime 'org.grails.plugins:asset-pipeline'
runtime 'org.grails.plugins:scaffolding' testCompile 'org.grails:grails-plugin-testing'
testCompile 'org.grails.plugins:geb' // Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0' console 'org.grails:grails-console'
}dependencyManagement {
imports {
mavenBom 'org.grails:grails-bom:' + grailsVersion
}
applyMavenExclusions false
}5.4.2 Working with Gradle Tasks
As mentioned previously thegrails command uses an embedded version of Gradle and certain Grails commands that existed in previous versions of Grails map onto their Gradle equivalents. The following table shows which Grails command invoke which Gradle task:| Grails Command | Gradle Task |
|---|---|
| clean | clean |
| compile | classes |
| package | assemble |
| run-app | bootRun |
| test-app | test |
| test-app --integration | integrationTest |
| war | assemble |
$ gradle test
grails command:$ grails gradle compileGroovy
$ grails
| Enter a command name to run. Use TAB for completion:
grails> gradle compileGroovy
...tasks task:gradle tasks
5.4.3 Grails plugins for Gradle
When you create a new project with the create-app command, a defaultbuild.gradle is created. The default build.gradle configures the build with a set of Gradle plugins that allow Gradle to build the Grails project:apply plugin:"war" apply plugin:"org.grails.grails-web" apply plugin:"org.grails.grails-gsp" apply plugin:"asset-pipeline"
war- The WAR plugin changes the packaging so that Gradle creates as WAR file from you application. You can comment out this plugin if you wish to create only a runnable JAR file for standalone deployment.asset-pipeline- The asset pipeline plugin enables the compilation of static assets (JavaScript, CSS etc.)
org.grails.grails-core- The primary Grails plugin for Gradle, included by all other plugins and designed to operate with all profiles.org.grails.grails-gsp- The Grails GSP plugin adds precompilation of GSP files for production deployments.org.grails.grails-doc- A plugin for Gradle for using Grails 2.0's documentation engine.org.grails.grails-plugin- A plugin for Gradle for building Grails plugins.org.grails.grails-plugin-publish- A plugin for publishing Grails plugins to the central repository.org.grails.grails-profile- A plugin for use when creating Grails Profiles.org.grails.grails-profile-publish- A plugin for publishing Grails profiles to the central repository.org.grails.grails-web- The Grails Web gradle plugin configures Gradle to understand the Grails conventions and directory structure.
