(Quick Reference)

1.1 What's new in Grails 3.2?

Version: 3.2.8

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

There are so many new features and novelties in GORM that we had to write its own independent What’s New Guide!

1.1.2 RxJava Support

In addition to RxGORM, support for RxJava has been added to the Grails framework via an RxJava plugin.

Reactive controllers with RxJava

The RxJava plugin allows you to return Observable 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 Angular Support

AngularJS Scaffolding

The angular 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.

Angular 2 Profile (3.2.1+)

Starting with Grails 3.2.1, the Angular 2 profile is available for use. To create a fresh application:

grails create-app test-ng -profile angular2

A multi-project build will be created with a separate project for the client and server applications. To make things easier, the tasks test, integrationTest, and bootRun have been created in the client application to make executing those tasks easier across the whole application.

Since Gradle executes tasks synchronously, and the bootRun task will never finish, it is important to execute it in parallel. At the root of the project:

./gradlew bootRun --parallel

This will start both the client and server side applications simultaneously.

For more information on how the new profile works, see the section in the user guide.

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

A child template can be specified as follows:

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
    }
}

The HAL support has also been improved with support for HAL pagination.

1.1.5 CORS Support

Starting with Grails 3.2.1, we have added support to configure the CORS support provided in Spring Boot.

This feature is disabled by default. Once enabled, the default setting is "wide open". To enable CORS configuration:

application.yml
grails:
    cors:
        enabled: true

To get more information on how to tighten down these settings to match your needs, visit the section on configuring CORS.

1.1.6 Grails Wrapper

The Grails wrapper is back starting with Grails 3.2.3!

You can use it the same way you use any Grails command inside a project.

./grailsw create-controller foo

1.1.7 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.8 Other Novelties

New Asciidoc Reference Documentation

The Grails user guide has been converted to use Asciidoctor for publishing, making it easier for users to contribute improvements to the documentation (Just click the "Improve this doc" link on the right!).

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

Refer to the run-script documentation for more information.

Commands, a feature previously only available in plugins, are now available to be created in applications

$ grails create-command MyCommand

Note that commands defined in applications are not executed the same way as commands defined in plugins. See the updated documentation on create-command for details.

REST Profile Refinements

The REST profile has been further refined including more sensible UrlMappings 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 your settings.groovy file. In addition, there are other new features useful for creating profiles. See the section on Profiles for the documentation.

Java 8 Date Support

Support for Java 8 date types has been added via a plugin. The tags formatDate and datePicker have been altered to support the new types. Support has been added to databinding to be able to successfully parse Java 8 dates. To take advantage of this functionality, add the new grails-java8 plugin to your application:

compile "org.grails.plugins:grails-java8"

If you are using hibernate and wish to persist the new date types, you should also add a dependency to hibernate-java8 as well:

compile "org.hibernate:hibernate-java8:<your hibernate version here>"