Micronaut with VS Code: Recommended Setup

Micronaut is a modern, lightweight Java framework. Many developers love using VS Code because it’s free, fast, and full of useful extensions. In this guide, we will go step-by-step to set up Micronaut development in Visual Studio Code (VS Code) in a simple and beginner-friendly way.

Micronaut with VS Code

Why Use Micronaut with VS Code?

  • Lightweight IDE: Faster startup compared to heavy IDEs.
  • Great extensions: Supports Java, Micronaut, debugging, and more.
  • Cross-platform: Works on Windows, Mac, and Linux.
  • Free and open-source

Combining Micronaut and VS Code makes microservice development smooth and efficient.


Prerequisites

Before starting, make sure you have:

  1. Java 21 JDK
  2. Micronaut CLI (Optional but useful)
    • Install using SDKMAN: sdk install micronaut
    • Or download from Micronaut.io.
  3. Visual Studio Code
    • Download and install from VS Code.

Step 1: Install Required VS Code Extensions

Open VS Code and go to the Extensions panel (left sidebar).

Search and install these extensions:

Extension NamePurpose
Java Extension PackProvides Java support, debugging, Maven, Gradle
Micronaut ToolsAdds Micronaut-specific support
Gradle for JavaGradle support for builds
Docker (optional)If you plan to containerize apps

You can also install the Java Extension Pack directly:


Step 2: Create a New Micronaut Project

Using Micronaut Launch

  1. Go to Micronaut Launch.
  2. Choose:
    • Language: Java
    • Java Version: 21
    • Build Tool: Gradle or Maven
    • Features: Add features like http-server, management, testcontainers if needed.
  3. Generate and download the zip file.
  4. Extract it and open the folder in VS Code.

Using Micronaut CLI (optional)

If you installed Micronaut CLI:

Open the generated folder in VS Code:


Step 3: Configure Java in VS Code

VS Code should automatically detect Java. If not:

  1. Go to Settings > Java: Home.
  2. Set it to your Java 21 JDK path.

Step 4: Build and Run Your Micronaut App

Build with Gradle

Use the integrated terminal (Ctrl+`) in VS Code:

Run the App

Alternatively, you can use VS Code’s Run and Debug option for better control.


Step 5: Create Your First Controller

Let’s create a simple Hello World REST API.

File: src/main/java/com/kscodes/micronautvscode/HelloController.java

Test it by opening:

http://localhost:8080/hello/World

You should see:


Step 6: Debugging in VS Code

  1. Open the Run and Debug panel.
  2. Click create a launch.json file.
  3. Select Java as environment.
  4. VS Code will generate the config.
  5. Click Run to start debugging.

Step 7: Enable Virtual Threads (Java 21 Feature)

In application.yml:

This allows Micronaut to use Java 21 virtual threads.


Step 8: Running Tests

Micronaut supports JUnit 5 out of the box.

File: src/test/java/com/kscodes/micronautvscode/HelloControllerTest.java

Run tests using VS Code’s Testing panel.


Summary

  • Install Java 21, Micronaut CLI, and VS Code.
  • Add Java and Micronaut extensions to VS Code.
  • Create, build, run, and debug Micronaut apps directly inside VS Code.
  • Leverage Java 21 features like virtual threads.

Useful Links


Stay tuned for more beginner-friendly Micronaut tutorials!