Goodbye Grails, Hello Micronaut #1: Multiproject

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

--

This is the first 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.

In this series, we will migrate various parts of the Grails application one by one. To be able to achieve that, we need to be able to extract parts of the current Grails application into separate libraries. This is best handled by using Gradle's multiproject layout. We'll be using Kordamp Gradle Plugin to achieve an easy-to-change multiproject structure.

First, move everything specific to your application into apps/<your-app-name>. We will use the name hello as a placeholder for your application's name in the following texts. So if your application is called hello then the new destination should be apps/hello. Do not move Gradle related files except the build.gradle file which will now take the name of the directory in which you have moved the file, e.g. hello.gradle. Grails Wrapper related files can be deleted.

This is how should the directory structure look like after moving the files:

Next, you need to create setting.gradle file which installs Kordamp Gradle Plugins

The rootProject.name should be composed of the original name of the application and the-root suffix to prevent name clash. Thanks to Kordamp Gradle Plugins, any directory within apps and libs will be now considered as a subproject automatically.

You will also need to create newbuild.gradle in the root directory. Replace the values in the following example with your own.

At last, explicitly declare the application class such as hello.Application in your Grails subproject apps/hello/hello.gradle because otherwise there will be a conflict in the Gradle plugins' configuration and that application won't start:

springBoot {
mainClassName = 'hello.Application'
}

You can now run the application with the following command to verify that the application still works.

./gradlew bootRun

In the next step, we will migrate Grails' configuration into Micronaut configuration objects.

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

--

--