2.3 Setting up an IDE

The application created in the previous section contains a “main class” located in src/main/java that looks like the following:

  1. import io.micronaut.runtime.Micronaut;
  2. public class Application {
  3. public static void main(String[] args) {
  4. Micronaut.run(Application.class);
  5. }
  6. }
  1. import io.micronaut.runtime.Micronaut
  2. class Application {
  3. static void main(String... args) {
  4. Micronaut.run Application.class
  5. }
  6. }
  1. import io.micronaut.runtime.Micronaut
  2. object Application {
  3. @JvmStatic
  4. fun main(args: Array<String>) {
  5. Micronaut.run(Application.javaClass)
  6. }
  7. }

This is the class that is run when running the application via Gradle or via deployment. You can also run the main class directly within your IDE if it is configured correctly.

Configuring IntelliJ IDEA

To import a Micronaut project into IntelliJ IDEA simply open the build.gradle or pom.xml file and follow the instructions to import the project.

For IntelliJ IDEA if you plan to use the IntelliJ compiler then you should enable annotation processing under the “Build, Execution, Deployment → Compiler → Annotation Processors” by ticking the “Enable annotation processing” checkbox:

Intellij Settings

Once you have enabled annotation processing in IntelliJ you can run the application and tests directly within the IDE without the need of an external build tool such as Gradle or Maven.

Configuring Eclipse IDE

If you wish to use Eclipse IDE, it is recommended you import your Micronaut project into Eclipse using either Gradle BuildShip for Gradle or M2Eclipse for Maven.

Micronaut requires Eclipse IDE 4.9 or above

Eclipse and Gradle

Once you have setup Eclipse 4.9 or above with Gradle BuildShip first run the gradle eclipse task from the root of your project then import the project by selecting File → Import then choosing Gradle → Existing Gradle Project and navigating to the root directory of your project (where the build.gradle is located).

Eclipse and Maven

For Eclipse 4.9 and above with Maven you need the following Eclipse plugins:

Once installed you need to import the project by selecting File → Import then choosing Maven → Existing Maven Project and navigating to the root directory of your project (where the pom.xml is located).

You should then enable annotation processing by opening Eclipse → Preferences and navigating to Maven → Annotation Processing and selecting the option Automatically configure JDT APT.

Configuring Visual Studio Code

Micronaut can be setup within Visual Studio Code. You will need to first install the The Java Extension Pack.

You can also optionally install STS to enable code completion for application.yml.

If you are using Gradle prior to opening the project in VSC you should run the following command from a terminal window:

  1. ./gradlew eclipse

Once the extension pack is installed and if you have setup terminal integration just type code . in any project directory and the project will be automatically setup.