3 Upgrading from Grails 3.3.x

3 Upgrading from Grails 3.3.x

You will need to upgrade your Grails version defined in .

Grails 3 app’s gradle.properties

gradle.properties

Grails 4 app’s gradle.properties

gradle.properties

  1. ...
  2. grailsVersion=4.0.0.BUILD-SNAPSHOT
  3. ...

Bump up GORM Version

If you were using , you will need to update the version defined in gradle.properties.

Grails 3 app’s gradle.properties

gradle.properties

  1. ...
  2. gormVersion=6.1.10.RELEASE
  3. ...

Grails 4 app’s gradle.properties

gradle.properties

  1. ...
  2. gormVersion=7.0.0.RC1
  3. ...

Spring 5 and Spring Boot 2.1

Grails 4.0 is built on Spring 5 and Spring Boot 2.1. See the and release notes if you are using Spring specific features.

Hibernate 5.4 and GORM 7.x

Grails 4.x supports a minimum version of Hibernate 5.4 and GORM 7.x. Several changes have been made to GORM to support the newer version of Hibernate and simplify GORM itself.

The details of these changes are covered in the GORM upgrade documentation.

Spring Boot 2.1 Actuator

Please check the Spring Boot Actuator documentation since it has changed substantially from Spring Boot 1.5 the version Grails 3.x used.

If you had configuration such as:

grails-app/conf/application.yml - Grails 3.3.x

  1. endpoints:
  2. enabled: false
  3. jmx:
  4. enabled: true
  5. unique-names: true

replace it with:

grails-app/conf/application.yml - Grails 4.x

  1. spring:
  2. jmx:
  3. unique-names: true
  4. management:
  5. endpoints:
  6. enabled-by-default: false

Previous versions of Grails used a reloading agent called . Since this library is no longer maintained and does not support Java 11 support for Spring Loaded has been removed.

build.gradle

Also you should configure the necessary excludes for Spring Developer Tools in application.yml:

  1. spring:
  2. devtools:
  3. restart:
  4. exclude:
  5. - grails-app/i18n/**
  6. - grails-app/conf/**

The above configuration prevents the server from restarting when views or message bundles are changed.

Spring Boot Gradle Plugin Changes

Grails 4 is built on top of Spring Boot 2.1. Grails 3 apps were built on top of Spring Boot 1.x.

Your Grails 3 app’s build.gradle may have such configuration:

buid.gradle

  1. bootRun {
  2. addResources = true
  3. ...
  4. }

Grails 4 apps are built on top of Spring Boot 2.1. Starting from Spring Boot 2.0, the addResources property no longer exists. Instead, you need to set the sourceResources property to the source set that you want to use. Typically that’s sourceSets.main. This is described in the .

Your Grails 4 app’s build.gradle can be configured:

buid.gradle

  1. bootRun {
  2. sourceResources sourceSets.main
  3. ...
  4. }

Building executable jars for Grails Plugins

:

If you had configuration such as:

buid.gradle | Grails 3

  1. // enable if you wish to package this plugin as a standalone application
  2. bootRepackage.enabled = false

replace it with:

buid.gradle | Grails 4

  1. // enable if you wish to package this plugin as a standalone application
  2. bootJar.enabled = false

Upgrading to Gradle 5

Grails 3 apps by default used 3.5. Grails 4 apps use Gradle 5.

To upgrade to Gradle 5 execute:

Due to changes in Gradle 5, transitive dependencies are no longer resolved for plugins. If your project makes use of a plugin that has transitive dependencies, you will need to add those explicitly to your build.gradle file.

If you customized your app’s build, other migrations may be necessary. Please check documentation.

H2 Web Console

If you were using GORM for Hibernate implementation in your Grails 3 app, you will need to upgrade to Hibernate 5.4.

A Grails 3 build.gradle such as:

build.gradle

  1. dependencies {
  2. ...
  3. compile "org.grails.plugins:hibernate5"
  4. compile "org.hibernate:hibernate-core:5.1.5.Final"
  5. }

will be in Grails 4:

build.gradle

  1. dependencies {
  2. ...
  3. compile "org.grails.plugins:hibernate5"
  4. compile "org.hibernate:hibernate-core:5.4.0.Final"
  5. }

Migrating to Geb 2.3

Geb 1.1.x (a JDK 1.7 compatible version) was the version shipped by default with Grails 3. Grails 4 is no longer compatible with Java 1.7. You should migrate to Geb 2.3.

In Grails 3, if your build.gradle looks like:

build.gradle

  1. dependencies {
  2. testCompile "org.grails.plugins:geb:1.1.2"
  3. testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
  4. testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
  5. }

In Grails 4, you should replace it with:

build.gradle

  1. buildscript {
  2. repositories {
  3. ...
  4. }
  5. dependencies {
  6. ...
  7. }
  8. }
  9. ...
  10. ..
  11. ...
  12. }
  13. apply plugin:"idea"
  14. ...
  15. ...
  16. apply plugin:"com.energizedwork.webdriver-binaries" (1)
  17. dependencies {
  18. ...
  19. testCompile "org.grails.plugins:geb" (4)
  20. testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion" (5)
  21. testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion" (5)
  22. testRuntime "org.seleniumhq.selenium:selenium-safari-driver:$seleniumSafariDriverVersion" (5)
  23. testCompile "org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion" (5)
  24. testCompile "org.seleniumhq.selenium:selenium-api:$seleniumVersion" (5)
  25. testCompile "org.seleniumhq.selenium:selenium-support:$seleniumVersion" (5)
  26. }
  27. webdriverBinaries {
  28. chromedriver "$chromeDriverVersion" (2)
  29. geckodriver "$geckodriverVersion" (3)
  30. }
  31. tasks.withType(Test) {
  32. systemProperty "geb.env", System.getProperty('geb.env')
  33. systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
  34. systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
  35. systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
  36. }

gradle.properties

  1. gebVersion=2.3
  2. seleniumVersion=3.12.0
  3. webdriverBinariesVersion=1.4
  4. hibernateCoreVersion=5.1.5.Final
  5. chromeDriverVersion=2.44 (2)
  6. geckodriverVersion=0.23.0 (3)
  7. seleniumSafariDriverVersion=3.14.0

Create also a Geb Configuration file at src/integration-test/resources/GebConfig.groovy.

src/integration-test/resources/GebConfig.groovy

Deprecated classes

The following classes, which were deprecated in Grails 3.x, have been removed in Grails 4. Please, check the list below to find a suitable replacement:

Grails-Java8

For those who have added a dependency on the grails-java8 plugin, all you should need to do is simply remove the dependency. All of the classes in the plugin have been moved out to their respective projects.

Profiles Deprecation

A few of the profiles supported in Grails 3.x will no longer be maintained going forward and as a result it is no longer possible to create applications when them in the shorthand form. When upgrading existing projects, it will be necessary to supply the version for these profiles.

  • org.grails.profiles:angularjsorg.grails.profiles:angularjs:1.1.2

  • org.grails.profiles:webpackorg.grails.profiles:webpack:1.1.6