Understanding Project Structure in Micronaut

Micronaut projects are designed to have a clean and modular structure. Whether you use Gradle or Maven as your build tool, the project organization remains similar.

In this post, we will focus on Micronaut projects created with Maven. I’ll explain each folder and file simply, so even if you’re completely new, you’ll quickly understand how everything fits together in a project structure in Micronaut.

Understanding Project Structure in Micronaut

Step 1 — Generate a Micronaut Project Using Maven

We’ll use the Micronaut CLI to generate a project using Maven.

Command:

Explanation:

  • com.kscodes.micronaut.sample → your package name.
  • --build=maven → we are using Maven instead of Gradle.
  • --lang=java → we are using Java.

Step 2 — Project Structure Overview

Once generated, your Micronaut Maven project will look like this:

Now, let’s break down each section.

Step 3 — Top-Level Files

1️⃣ pom.xml

  • This is the Maven build configuration file.
  • It defines dependencies, plugins, and project info.

Example snippet:

All your Micronaut dependencies and plugins go here.

Much like Gradle’s build.gradle, but in XML format.

2️⃣ mvnw and mvnw.cmd

  • These are the Maven Wrapper scripts.
  • They ensure anyone can build the project without having Maven installed globally.
  • mvnw is for Mac/Linux, and mvnw.cmd is for Windows.

3️⃣ README.md

  • Simple file explaining how to run and build your project.

Step 4 — src/main Folder

1️⃣ src/main/java/

  • All your Java application source code lives here.

Example file:
Application.java

This is the entry point for your Micronaut application.

2️⃣ src/main/resources/

Contains all your resource files such as configurations and logging:

application.yml

  • Used for Micronaut configuration.

Example:

logback.xml

  • Used to configure logging for your application.

Step 5 — src/test Folder

This folder contains your test cases and test configurations.

1️⃣ src/test/java/

  • You’ll write your JUnit or Micronaut tests here.

Example:

2️⃣ src/test/resources/

  • Holds any test-specific resources like alternative configurations.

Step 6 — How to Build and Run

Build the project:

./mvnw clean package

Run the application:

./mvnw mn:run

You can also run the JAR directly from the target/ folder after packaging.

Step 7 — Quick Recap

File/FolderPurpose
pom.xmlBuild configuration (Maven)
mvnwMaven wrapper
Application.javaApplication entry point
application.ymlMicronaut configuration
logback.xmlLogging configuration
src/test/javaUnit tests

Conclusion

The Micronaut project structure is very easy to understand once you break it down:

  • Source code goes into src/main/java.
  • Configuration goes into src/main/resources.
  • Tests live inside src/test/java.
  • Build configuration stays inside pom.xml.

Even though Micronaut feels modern and powerful, it keeps things very developer-friendly and familiar — especially if you’ve used Maven or Java before.

Reference : Micronaut Docs