Updating to a new framework version often needs a lot of work and investigation how to fix problems that may arise. Usually there are upgrade guides that take you most of the way and make upgrading only a grind.
This also true for Grails and our upgrade experience with it. Often there are parts where you have to invest extra work and creativity. The current upgrade of our application from 2.4.5 to 3.3.8 is no exception:
The grind
The major changes and upgrade notes are part of the documentation so I will only mention them briefly:
- Switch to the gradle build system
- Using YAML as main configuration
- Migration from filters to interceptors
- New testing framework (partly optional because you can still use the old mixin framework with a plugin)
- Package name changes
- Former core features are now available as plugins like gsps, datasource and GORM
- Functional tests need to use Spock+Geb or you will face weird problems and need to do extra work (we had selenium tests using selenium-server before)
- Integration tests work differently so work needs to be done to migrate them
- Logging using Lockback
- Entities often need a @Entity annotation
- Move some files to new Locations
The tricky stuff
- A service named CounterService conflicts with spring boot autowiring so we had to rename it
- Our TagLib tests using JUnit4 were failing with obscure errors, porting them to Spock fixed them.
- We have so many dependencies that running the application with gradle:bootRun fails with:
Createprocess error=206; the filename or extension is too long
Fortunately addinggrails { pathingJar = true }
to build.gradle fixes the issue - Environment variables for gradle:bootRun are swallowed if not prefixed with “grails.”. We are using environment variables to customize running the application on the dev machines.
The hard parts
The most painful part was two central plugins we are using not being available anymore: shiro and searchable.
Shiro
For shiro there are some initial ports that work well for our needs, so the challenge was mostly finding the most fitting one of the forks on github. We went with the fork of Alin Pandichi and forked it ourselves to upgrade some version definitions.
Searchable becomes ElasticSearch
The real odyssee began looking for a replacement of the abandoned searchable plugin. Fortunately there is the compelling ElasticSearch-plugin which uses almost the same API as the searchable plugin:
The plugin focus on exposing Grails domain classes for the moment. It highly takes the existing Searchable Plugin as reference for its syntax and behaviour.
Unfortunately, we were unable to get it to work with our project trying many different versions, so we decided to fork and fix it for us. The main problems were:
- Essentially, it does not work properly with hibernate as a data store because it chokes on the JavaAssist proxies hibernate often creates for domain objects.
- An easy to fix concurrency issue
- Not flexible enough converters
After a lot of debugging and a couple of fixes and the new feature of being able to use a spring bean as a converter we had search working smoothly and better than ever.
Wrapping it all up
The upgrade of our application to the newest incarnation of Grails was a rocky ride and took us quite some time.
On the other hand the framework got a lot better. Especially gradle is much better to manage than the previous build system.
So we are looking forward to a much better and robust development experience in the future and hope for some less revolutionary releases and easier upgrades.
One thought on “Bringing your Grails app from 2.4 to 3.3”