1 Introduction - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.2.0.RC1
Table of Contents
1 Introduction
Java web development as it stands today is dramatically more complicated than it needs to be. Most modern web frameworks in the Java space are over complicated and don't embrace the Don't Repeat Yourself (DRY) principles.Dynamic frameworks like Rails, Django and TurboGears helped pave the way to a more modern way of thinking about web applications. Grails builds on these concepts and dramatically reduces the complexity of building web applications on the Java platform. What makes it different, however, is that it does so by building on already established Java technologies like Spring and Hibernate.Grails is a full stack framework and attempts to solve as many pieces of the web development puzzle through the core technology and its associated plugins. Included out the box are things like:- An easy to use Object Relational Mapping (ORM) layer built on Hibernate
- An expressive view technology called Groovy Server Pages (GSP)
- A controller layer built on Spring MVC
- An interactive command line environment and build system based on Gradle
- An embedded Tomcat container which is configured for on the fly reloading
- Dependency injection with the inbuilt Spring container
- Support for internationalization (i18n) built on Spring's core MessageSource concept
- A transactional service layer built on Spring's transaction abstraction
1.1 What's new in Grails 3.2?
This section covers all the new features introduced in Grails 3.2.1.1.1 GORM 6 Suite
Grails 3.2 comes with GORM 6.0, the biggest release of GORM ever! GORM 6 includes the following new features:- GORM for Neo4j 3.0 / Bolt Driver support
- GORM for MongoDB 3.2
- RxGORM - GORM for RxJava
- RxGORM for REST built on RxNetty
- RxGORM for MongoDB Rx Driver
- Universal Multiple Data Sources Support
- Multi Tenancy Support
- Spring Container Free Bootstrapping
- Improved Unit Testing
- Unified Configuration API
- New Standalone Documentation
1.1.2 RxJava Support
In addition to RxGORM, support for RxJava has been added to the Grails framework via an RxJava pluginReactive controllers with RxJava
The RxJava plugin allows you to returnObservable responses from controllers and integrates seamlessly with RxGORM to make it possible handle requests reactively, in a non-blocking manner. For example:def show() {
String author = params.author
Book.get(params.id)
.map { Book book ->
rx.render view:"book", model:[book:book, author:author]
}
}Server Sent Events with RxJava
It is now possible to easily issue responses that return Server Sent Events with Grails and RxJava:def index() {
rx.stream { Subscriber subscriber ->
for(i in (0..5)) {
if(i % 2 == 0) {
subscriber.onNext(
rx.render("Tick")
)
}
else {
subscriber.onNext(
rx.render("Tock")
) }
sleep 1000
}
subscriber.onCompleted()
}
}See the sample application for a demonstration of Server Sent Events in action
1.1.3 AngularJS 1.0 Scaffolding
Theangular profile has been refined and now also includes a new Angular Scaffolding plugin.The Angular scaffolding plugin adds an ng-generate-all command which will generate the necessary AngularJS 1.x client code to perform CRUD operations in conjunction with a Grails 3 backend.Not only does this serve as a useful tool to get up and running quickly, but (like previous versions of scaffolding) it is a great way for developers to learn how to integrate AngularJS and Grails 3.Support for Angular 2 is planned for the future.
1.1.4 JSON Views 1.1
Version 1.1 of the JSON Views plugin is included with Grails 3.2's "rest-api" profile and includes a number of new features. Below are some of the highlights:Template Inheritance
It is now possible for a child JSON template to specify a parent template, thus allowing better template composition. For example given the following parent:// grails-app/views/_parent.gson
model {
Object object
}
json {
hal.links(object)
version "1.0"
}inherits template:"parent"
model {
Person person
}
json {
name person.name
}Global and Default Templates
Global templates can now be created for any GORM custom types. This allows adding support for external libraries such as JodaTime or custom types provided by datastores such as MongoDB (example GeoJSON).A global template is simply another JSON template that is named after the class name. See for example the GeoJSON templates.In addition it is now possible to provide a fallback template named/object/_object.gson that is used if no other template is found.Better HAL Support
The HAL support has been expanded and now includes greater control over_embedded and _links, for example:model {
Book book
}
json {
hal.links(self: book )
hal.embedded(authors: book.authors)
hal.inline(book) {
pages 300
}
}1.1.5 Updated Dependencies
Grails 3.2 ships with the following dependency upgrades:- Hibernate 5.1.1 (now the default version of Hibernate for new applications)
- Spring Framework 4.3.1
- Spring Boot 1.4.0
- Gradle 3.0
1.1.6 Other Novelties
New default date data binding format
Dates formatted like "1970-01-01T00:00:00.000Z" will now be successfully parsed by default. The format is used by common JavaScript libraries.The run-script command from Grails 2 is back
The run-script command makes a return! It is now possible to run Groovy scripts that are wrapped in a Grails context using Grails 3:$ grails run-script my-groovy-script.groovy
REST Profile Refinements
The REST profile has been further refined including more sensibleUrlMappings and mime type configuration designed specifically for REST applications.Ability to skip the Bootstrap process with a system property
When the Grails runtime is started, it will now execute*Bootstrap.groovy classes conditionally. If the system property grails.bootstrap.skip is set to true, the classes will not be executed for that run.Changes to data binding with the body of a request
To be more inline with the HTTP/1.1 specification, request bodies in GET and DELETE requests will be ignored for data binding. The request body will also be ignored if the specified content length is 0.Profile improvements
It is now possible to specify credentials for repositories used for profile resolution in yoursettings.groovy file. See the section on profiles for documentation.
1.2 What's new in Grails 3.1?
Grails 3.1 includes the following new features.Spring Boot 1.3 and Spring 4.2
Grails 3.1 has been upgraded to Spring Boot 1.3 and Spring 4.2.1.2.1 Improvements to Grails 3 Profiles
Profile Publishing and Repositories
The following improvements are available in Grails profiles:- Profiles are now published as regular JAR files to any Maven compatible repository (Artifactory, Nexus etc.).
- Additional profiles can be created easily with the new create-profile command.
- Profiles can now contribute to the generation of the build
- Profiles can now have one or many features
1.2.2 REST API and AngularJS Profiles
REST Profile
A new profile is available designed for the creation of pure REST applications without a UI.To create a REST application use therest-api profile as an argument to create-app:$ grails create-app myapp --profile=rest-api
In earlier milestones this profile was named web-api. The profile has been renamed rest-api which more appropriately describes its purpose.
Then start interactive mode to see the available commands for the profile:$ cd myapp $ grails
create-domain-resource- Creates a domain class annotated with the Resource annotation)create-restful-controller- Creates a controller that extends RestfulController.
JSON and Markup Views
The REST profile includes the ability to define JSON and Markup views and thebuild.gradle features the ability to compile these views for production use.The REST profile also creates JSON views to render the index action and common commands such as generate-views have been overridden to generate JSON views.AngularJS Profile
An initial version of the AngularJS profile is now available, making it easier to create and integrate AngularJS with Grails 3 applications.To create a Grails 3 AngularJS application use theangular profile as an argument to create-app:$ grails create-app myapp --profile=angular
$ cd myapp $ grails
create-ng-component, create-ng-controller etc. that help you get going creating an AngularJS application.The build.gradle is also preconfigured with the necessary Gradle plugins to integrate AngularJS with Asset Pipeline. The created Angular application can be found in grails-app/assets/javascripts.
1.2.3 GORM 5 Suite
Grails 3.1 ships with GORM 5 which is a brand new release of GORM supporting the following technologies:- Hibernate 3, 4 and 5 - for SQL databases GORM for Hibernate now supports the latest Hibernate 5.x release
- MongoDB 3.x - GORM for MongoDB has been upgraded to the MongoDB 3.x Java driver and supports codec based persistence
- Neo4j 2.3.x - GORM for Neo4j has been significantly improved and support the latest release of Neo4j
- Cassandra - GORM for Cassandra supports the latest 2.0.x drivers
1.2.4 Plugin Publishing Plugins
New Gradle plugins are available to simplify publishing of plugins and profiles.To utilize the plugin apply theorg.grails.grails-plugin-publish plugin (after any existing Grails plugins for Gradle):apply plugin: "org.grails.grails-plugin" apply plugin: "org.grails.grails-plugin-publish"
grails-profile-publish plugin can be used instead:apply plugin: "org.grails.grails-profile" apply plugin: "org.grails.grails-profile-publish"
grailsPublish {
user = 'user'
key = 'key'
githubSlug = 'foo/bar'
license {
name = 'Apache-2.0'
}
title = "My Plugin Title"
desc = "My Plugin Description"
developers = [johndoe:"John Doe"]
}user and key are your Bintray credentials. With this done you can continue to use bintrayUpload to publish your plugin. In addition, if you wish to update the Grails plugin portal, you simply need to configure your grails.org credentials:grailsPublish {
…
portalUser = "..."
portalPassword = "..."
}notifyPluginPortal to update the Grails.org Plugins website:gradle notifyPluginPortal
