DEV Community

Eric Helgeson
Eric Helgeson

Posted on • Updated on

Grails 4 Upgrade Notes

Grails 4 is the next iteration of the Grails web framework. Grails is a developer friendly framework built on top of Spring-boot, Groovy, and now Micronaut.

Status

Grails 4 is released!

I've ported a non-trivial app from Grails 3.3.9 to 4.0.0 as well as updated to JDK11. The total effort was only a few hours - welcome news to many who are upgrading.

Initial app startup time is about 15 seconds - 2x faster than the same app in Grails 3.3.9.

Reloading has changed and there are a few options. The default option is from spring-dev-tools - fast restart. This restarts your app faster then a normal restart, but still can be extremely slow for large projects.

Hot reloading options are JRebel - a paid option that works for JDK8/11 - or spring-loaded though it only supports JDK8 and is no longer maintained. Instructions for spring-loaded

IDE Support all works in Grails 4 (same as 3.3.9) - IntelliJ is still my recommended IDE for any Grails, Groovy, or Java developer.

Updates

There are tons of updates to Grails 4 and the frameworks it builds upon. Here's a list of updates and release notes you should review if you're updating your apps.

Install

SDKMan makes installing and managing a JVM and many frameworks a snap:

sdk install java 11.0.2-open
sdk install grails 4.0.3

Plugins

Plugins are an essential part of the Grails developer experience. Luckily many plugins that worked in Grails 3 work out of the box in Grails 4 - or with only slight modifications due.

Working Plugins

compile "org.springframework.boot:spring-boot-starter-data-redis"
compile "org.springframework.session:spring-session-data-redis"
  • Spring-Websocket
compile "org.grails.plugins:grails-spring-websocket:2.5.0.RC1"
  • Grails-Quartz
buildscript {
    dependencies {
        classpath 'org.grails.plugins:quartz:2.0.13' // Needed to compile *Job classes
    }
}

dependencies {
    compile 'org.grails.plugins:quartz:2.0.13'
    compile 'org.quartz-scheduler:quartz:2.2.1' // Is not pulled in by default
}
  • Database Migration Plugin 3.1.0.RC1

  • Asset-Pipeline 3.1.0

  • External Config

    • Works - use RC1+
    compile 'org.grails.plugins:external-config:2.0.0'

Not working

Resolved

  • Asset Pipeline Handlebars issue:
    • Needed to update to change //= require handlebars/handlebars.js to //= require handlebars-runtime
2019-01-13 16:59:42.280  WARN --- [nio-8080-exec-1] asset.pipeline.DirectiveProcessor        : Unable to Locate Asset: /handlebars/handlebars.js
Warning: Nashorn engine is planned to be removed from a future JDK release
  • Gson Views
    • Resolved.
    • Unable to render json with simple objects (just get null response)
    • Domain classes dont render:
  Model variable [someDomain] of with value [Description] type [com.x.SomeDomain] is not of the correct type [com.x.SomeDomain]. Stacktrace follows:

Other notes Notes

  • Hot reload for JDK8 only

    • spring-loaded supports only up to JDK8.
    • Fast reload takes about 5-6 seconds (hopefully can improve)
  • org.grails:grails-datastore-rest-client no longer maintained

    • Use a different http client such as
      • micronaut-http-client, http-builder-ng, feign, okhttp, etc
    • Or use the old unmaintained GORM 6 version:
compile('org.grails:grails-datastore-rest-client:6.1.9.RELEASE'){
    exclude group:'org.grails', module:'grails-plugin-converters'
}
Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead
// and
HHH020100: The Ehcache second-level cache provider for Hibernate is deprecated.  See https://hibernate.atlassian.net/browse/HHH-12441 for details.
  • Hide them in logback.groovy
    • logger('org.hibernate.orm.deprecation', ERROR, ['STDOUT'], false)

Notes or tips of your own?

Join us over on the grails-community slack channel or comment below!

Top comments (10)

Collapse
 
hybridprogrammer profile image
Jason Heithoff

Great notes, wanted to add some of mine:

Spring Security CAS will now require this dependency:

compile group: 'org.springframework.security', name: 'spring-security-cas', version: '5.1.5.RELEASE'

An older plugin of mine was using the older hystrix library which isn't supported in spring boot 2 so:

Change:

compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-hystrix', version: '*'

to

compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix', version: '2.1.2.RELEASE'

Collapse
 
amitpawarrx profile image
amit-pawar-rx

@eric can you please help me to underdstand how to work with the resultTranformer() in UTC , its giving error with respect to criteria.

groovy.lang.MissingMethodException: No signature of method: grails.gorm.CriteriaBuilder.resultTransformer() is applicable for argument types: (org.hibernate.transform.AliasToEntityMapResultTransformer) values: [org.hibernate.transform.AliasToEntityMapResultTransformer@3213c334]
at org.grails.datastore.gorm.query.criteria.AbstractCriteriaBuilder.invokeMethod(AbstractCriteriaBuilder.java:302)

Collapse
 
erichelgeson profile image
Eric Helgeson

Stackoverflow may be a better place to ask questions - i'm not sure what your question has to do with this post.

Collapse
 
robertoschwald profile image
Robert Oschwald

Grails Cache Plugin: Not working, yet. github.com/grails-plugins/grails-c...

Grails Schwartz Plugin: Not working, yet. github.com/agileorbit/grails-schwa...

Audit-Logging Plugin: Not working, yet. WIP. github.com/robertoschwald/grails-a...

Works:

Db-Migration Plugin: 3.1.0.RC1

Asset-Pipeline-Grails: 3.0.10

Collapse
 
erichelgeson profile image
Eric Helgeson

Updated with this list, thanks!

Collapse
 
miguelabautista profile image
miguel bautista • Edited

Hello. Is there a way to avoid running Bootstrap again after changing a class? my problem is that I have a lot of initialization processes there. thanks

Collapse
 
tirlaalin profile image
Tirla-Alin

Great post!

Collapse
 
kanwar007 profile image
vijaykanwar

Hi Eric

We need to update grail 2.3.8 to latest 4.
What is the best approach to do that?
is any think you can help me on this ?

Thanks
vijay Kanwar

Collapse
 
erichelgeson profile image
Eric Helgeson

Hi Vijay - I would start by creating a fresh Grails 4 app and pulling over a few parts of the old app at a time - fixing errors as you go. If you find anything that would be useful here - let me know! Also jump on the Grails Slack channel if you have questions.

Collapse
 
purpleraven profile image
purpleraven

Best information about upgrade to Grails 4