Search code examples
micronautjava-module

How to break down a Java Micronaut application into multiple java modules?


I am from .net background and new to java. I have started exploring java micronaut framework and started building a mid size application using it. I want to break down functionality into following multiple modules (java module).

  • WebInterface
  • Application Services
  • Domain Services
  • Data Access Services
  • Shared

But when I created a new micronaut project using CLI, it created project without any module.

enter image description here

Though I deleted the src folder from root folder altogether but I am not sure about the gradle related files created there. I have copied the content of root's build.gradle file to individual module's build.gradle files (with some minor adjustments)

Am I on the right track or there is other ways to divide micronaut application into multiple modules?


Solution

  • But when I created a new micronaut project using CLI, it created project without any module.

    That is the intended behavior of our CLI.

    I want to break down functionality into following multiple modules (java module)...

    You should do that with Gradle subprojects. You will have to author that yourself. The Micronaut CLI isn't involved in that, except you can use the dependencies generated by the CLI as a starting point.

    Am I on the right track or there is other ways to divide micronaut application into multiple modules?

    You are kind of on the right track. You will probably want a Gradle multi-project build with a subproject that uses the io.micronaut.application Gradle plugin (https://plugins.gradle.org/plugin/io.micronaut.application) and some of the others will likely use the io.micronaut.library Gradle plugin (https://plugins.gradle.org/plugin/io.micronaut.library).