The expectation of this blog is to guide you through setting up a multiple-module project from the first micronaut application. The anticipated structure after following this blog will be:
In this blog post, we will explore the step-by-step process of setting up a multiple-module project with Micronaut. Let’s get started!
Why Multiple Modules?
Breaking down a monolithic application into smaller, more manageable modules brings several advantages. It promotes code reusability, makes the project more maintainable, and enables parallel development by allowing different teams to work on separate modules independently. Micronaut’s support for multiple modules makes it an excellent choice for projects of all sizes.
plugins{id("com.google.devtools.ksp")version"1.9.20-1.0.14"id("io.micronaut.application")version"4.2.0"id("io.micronaut.aot")version"4.2.0"}version="0.1"group="com.melon"dependencies{ksp("io.micronaut:micronaut-http-validation")ksp("io.micronaut.serde:micronaut-serde-processor")implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")implementation("io.micronaut.serde:micronaut-serde-jackson")implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")compileOnly("io.micronaut:micronaut-http-client")runtimeOnly("ch.qos.logback:logback-classic")runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")testImplementation("io.micronaut:micronaut-http-client")}application{mainClass.set("com.melon.ApplicationKt")}graalvmNative.toolchainDetection=falsemicronaut{runtime("netty")testRuntime("junit5")processing{incremental(true)annotations("com.melon.*")}aot{// Please review carefully the optimizations enabled below
// Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details
optimizeServiceLoading=falseconvertYamlToJava=falseprecomputeOperations=truecacheEnvironment=trueoptimizeClassLoading=truededuceEnvironment=trueoptimizeNetty=true}}
Attempt running ./gradlew run, and your Micronaut application should function as usual.
Conclusion
With the foundation in place, you can now easily add more modules, such as app/module-postgresql or core/module-logging, extending the modularity and scalability of your Micronaut project.