Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 38 ยท Getting Started

Creating a Micronaut App

Create a Micronaut project with the mn CLI or Micronaut Launch, pick the language, build tool and features, and understand what the generator writes.

You can start a Micronaut project three ways: the mn command-line tool, the web page Micronaut Launch (the same generator with a form), or an IDE wizard that calls the same service. All of them produce the same thing: a small project with a build file, an Application class, a configuration file and a test. This lesson walks through the choices you make when generating one and explains why each choice matters.

The real generator is not available on this site, so the commands are read-only. The two runnable examples are Java stand-ins that imitate what a generator does: laying out files from your answers, and resolving features that depend on other features.

Prerequisites

You need a JDK (Micronaut 4 requires Java 17 or newer; Java 21 or 25 are good choices) and a build tool. The generated project includes the Gradle or Maven wrapper, so you do not install Gradle or Maven separately. For native images you also need GraalVM, covered in the chapter on native images. Check your JDK:

Terminal
java -version

Using the mn CLI

The CLI is installed with SDKMAN, Homebrew, Chocolatey or a downloadable zip. The core command is mn create-app:

Terminal
mn create-app com.example.shop --build=gradle --lang=java --test=junit

The first argument is the package-qualified name. The last segment, shop, becomes the project name and the first segment group becomes the base package. Useful options:

Option Meaning Typical values
--build Build tool gradle, gradle_kotlin, maven
--lang Language java, kotlin, groovy
--test Test framework junit, spock, kotest
--features Extra modules data-jdbc,flyway,jackson-xml
--jdk Java version 17, 21

You can also create other kinds of project: mn create-function-app for serverless functions, mn create-cli-app for command-line tools, mn create-messaging-app for Kafka or RabbitMQ consumers, and mn create-grpc-app for gRPC services. Inside a project, mn create-controller, mn create-bean and mn create-client generate classes with the right annotations.

Using Micronaut Launch

Launch runs in a browser, but it is only a front end to the same generator. You choose an application type, language, build tool, Micronaut version and features, then download a zip or push the code to a Git repository. Launch also has an API, so the CLI is simply one more client of it. Use whichever you prefer; the output is identical for the same choices.

Features

A feature is a prepackaged bundle of dependencies, configuration and sometimes sample code. Choosing data-jdbc adds Micronaut Data's JDBC module, a connection pool, and a datasource section in application.yml. Choosing flyway adds migrations support and a db/migration folder. Features can depend on each other, and the generator adds whatever is required.

Choices when you generate

Build tool Gradle or Maven.
Language Java, Kotlin or Groovy.
Features Data, security, cloud, tracing, and more.
Test framework JUnit, Spock or Kotest.

You can add features later by editing the build file.

1 / 2

What gets generated

For mn create-app com.example.shop --build=gradle --lang=java, you get roughly this:

Text
shop/
  build.gradle.kts        (or build.gradle)
  settings.gradle.kts
  gradle.properties
  gradlew, gradlew.bat, gradle/wrapper/
  micronaut-cli.yml
  src/main/java/com/example/Application.java
  src/main/resources/application.properties
  src/main/resources/logback.xml
  src/test/java/com/example/ShopTest.java
  README.md

micronaut-cli.yml records your choices so that later mn create-controller commands generate Java code in the right package. The build file applies the Micronaut Gradle plugin, which wires in the annotation processor, the test runner and tasks such as run and nativeCompile.

Maven projects get a pom.xml whose parent is micronaut-parent, which manages dependency versions in the same way Spring Boot's parent POM does.

Stand-in 1: a project generator

This program takes the same kinds of answers and prints the file tree a generator would produce. It is only an imitation, but it shows how a handful of options decide the layout: the file extension follows the language, the build file name follows the build tool, and the package becomes folders.

Java Imitating mn create-app

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Stand-in 2: resolving features

When you tick data-jdbc, the generator must also pull in the connection pool. This stand-in models features as a small graph and resolves what a choice really includes. The feature names mimic real ones, but the table is invented for the demonstration.

Java Features that depend on features

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Notice that jdbc-hikari appears once even though two features need it. A real generator also checks incompatible combinations and picks the right library version for the Micronaut release you selected.

After generating

Open the project in your IDE and import the Gradle or Maven build. Make sure annotation processing is enabled, because Micronaut depends on it. IntelliJ IDEA enables this when it imports a Micronaut project; if you see "No bean of type" errors in the editor that the build does not report, turn it on under the compiler settings. Then try the first build:

Terminal
./gradlew run          # Gradle
./mvnw mn:run          # Maven

You will build and run your first endpoint in the first controller lesson. The layout is explained in Project Structure and Configuration.

Commit the wrapper files (gradlew, gradle/wrapper, or mvnw). They let teammates and CI use the same build tool version without installing anything.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What do Micronaut Launch and the mn CLI have in common?

    Launch has an API and the CLI is another client, so the same choices give the same output.
  2. 2. What is a Micronaut feature?

    Features such as data-jdbc or flyway add the right dependencies and starter configuration.
  3. 3. Why should annotation processing be enabled in your IDE?

    Without the annotation processor, bean definitions are not generated and the IDE may report missing beans.
  4. 4. Which file stores your generator choices for later mn create-controller commands?

    micronaut-cli.yml remembers language, build tool and package so generated classes match.

Summary

  • Generate projects with mn create-app, Micronaut Launch or an IDE wizard.
  • You choose language, build tool, test framework, JDK and features.
  • Features bundle dependencies and configuration, and may pull in other features.
  • The output has a build file, an Application class, application.properties, a logging config and a test.
  • Keep annotation processing enabled and commit the build wrapper.

Next: Project Structure and Configuration