Goodbye Grails, Hello Micronaut #3: Static Compilation

Vladimír Oraný
Stories by Agorapulse
2 min readAug 3, 2021

This is the third post in a series that will guide you through the migration from Grails to Micronaut. This guide requires your application to be based on Grails 4.x or later.

Switching the frameworks is never easy, even for the ones which are very close to each other. As an extra layer of security to ensure the migration won't get wrong, let's adda static compilation of the application globally. This will also help us in the next steps to purify the domain model usage. The whole process has been already described in the following post so, please, take the detour and read that guide first.

As we would like to apply the static compilation for every application and library in the project, let's update our settings.gradle projects section as follows:

settings.gradle

These extra lines will ensure that every subproject in apps and libs directory will have groovy and java-library plugin applied.

Then let's configure the Enterprise Groovy dependency which will help us to apply the static compilation globally. Add the following lines into your build.gradle file:

build,.gradle

Create the configuration file mentioned above in config/groovy/conventions.groovy :

Now the easy part is over and one of the most difficult part is ahead.

If you have configured everything properly then you may be facing compilation issues when you run ./gradlew classes command from the terminal. The drawback of using Enterprise Groovy is that the static compilation is not clear to the IDE so I would recommend adding @CompileStatic or @GrailsCompileStatic annotations to the classes which fail to compile to see the errors directly inside your IDE. You need to annotate the parts which cannot be compiled statically with @CompileDynamic but, please, keep the scope of dynamic compilation at the minimal level. As a reward, you will get an application that is less prone to errors and you can feel safer about all the refactoring.

In the next step, we will prepare datasets for your domain classes as the foundation for the tests we will write later to ensure the smooth migration.

Table of Contents

  1. Multiproject
  2. Configuration
  3. Static Compilation
  4. Datasets
  5. Marshalling
  6. Domain Classes
  7. Services
  8. Controllers
  9. Micronaut Application
  10. Micronaut Data

Sources & Discussion

--

--