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.

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:
- Java 21 JDK
- Micronaut CLI (Optional but useful)
- Install using SDKMAN:
sdk install micronaut
- Or download from Micronaut.io.
- Install using SDKMAN:
- 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 Name | Purpose |
---|---|
Java Extension Pack | Provides Java support, debugging, Maven, Gradle |
Micronaut Tools | Adds Micronaut-specific support |
Gradle for Java | Gradle support for builds |
Docker (optional) | If you plan to containerize apps |
You can also install the Java Extension Pack directly:
1 2 3 |
ext install vscjava.vscode-java-pack |
Step 2: Create a New Micronaut Project
Using Micronaut Launch
- Go to Micronaut Launch.
- Choose:
- Language: Java
- Java Version: 21
- Build Tool: Gradle or Maven
- Features: Add features like
http-server
,management
,testcontainers
if needed.
- Generate and download the zip file.
- Extract it and open the folder in VS Code.
Using Micronaut CLI (optional)
If you installed Micronaut CLI:
1 2 3 |
mn create-app com.kscodes.micronautvscode --java-version 21 |
Open the generated folder in VS Code:
1 2 3 |
code com.kscodes.micronautvscode |
Step 3: Configure Java in VS Code
VS Code should automatically detect Java. If not:
- Go to Settings > Java: Home.
- 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:
1 2 3 |
./gradlew build |
Run the App
1 2 3 |
./gradlew run |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
package com.kscodes.micronautvscode; import io.micronaut.http.annotation.*; @Controller("/hello") public class HelloController { @Get("/{name}") public String sayHello(String name) { return "Hello, " + name + "!"; } } |
Test it by opening:
http://localhost:8080/hello/World
You should see:
1 2 3 |
Hello, World! |
Step 6: Debugging in VS Code
- Open the
Run and Debug
panel. - Click create a launch.json file.
- Select
Java
as environment. - VS Code will generate the config.
- Click Run to start debugging.
Step 7: Enable Virtual Threads (Java 21 Feature)
In application.yml
:
1 2 3 4 5 6 |
micronaut: executors: io: type: virtual |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package com.kscodes.micronautvscode; import io.micronaut.test.extensions.junit5.annotation.MicronautTest; import org.junit.jupiter.api.Test; import jakarta.inject.Inject; import io.micronaut.http.client.HttpClient; import io.micronaut.http.client.annotation.Client; import static org.junit.jupiter.api.Assertions.*; @MicronautTest class HelloControllerTest { @Inject @Client("/") HttpClient client; @Test void testHelloEndpoint() { String response = client.toBlocking().retrieve("/hello/World"); assertEquals("Hello, World!", response); } } |
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!