Create a Project

This chapter explains the different ways to create a new Application, Library or Mock project. If you want to create a VEE Port project, refer to the Create a VEE Port section.

Note

The different project creation systems do not produce exactly the same project content and structure. Especially, the IntelliJ IDEA wizard produces a simple project whereas the Android Studio, Command Line Interface and Eclipse wizards create multi-projects builds. Both structures (single and multi projects) can be used, the recommended one depends on the context (components, size of the project, …). Refer to the official Gradle documentation for more information.

The creation of a project with IntelliJ IDEA is done as follows:

  • Click on File > New > Project….

  • Select MicroEJ in Generators list on the left panel.

  • Fill the name of the project in the Name field.

  • Select the location of the project in the Location field.

  • Select the project type. If there is no button for your project type, click on Other button and select it in the drop-down list.

  • If you selected Application project type, you can check This is a kernel application checkbox if your Application is a Kernel.

  • Fill the version of the artifact to publish in the Version field.

  • Fill the group of the artifact to publish in the Group field.

  • Fill the name of the artifact to publish in the Artifact field.

  • Select the JVM used by Gradle in the JDK combobox.

  • Check the Add sample code checkbox.

  • Click on Create button.

Project Creation in IntelliJ IDEA

Project Creation in IntelliJ IDEA

Note

The Gradle project created by the wizard uses Gradle Wrapper with Gradle version 8.10.2. Refer to the Gradle Wrapper section for more information.

Note

By default, IntelliJ IDEA automatically saves any file change, but requires the user to explicitly trigger the reload of a Gradle project when its configuration has changed. Therefore, when the configuration of a Gradle project has been updated, you have to click on the reload icon button which appears on the right of the editor:

Gradle Project reload in IntelliJ IDEA

Gradle Project reload in IntelliJ IDEA

You can also configure IntelliJ IDEA to automatically reload a Gradle project after a change. Refer to the How To Automatically reload a Gradle project section for more information.

Warning

When reloading your Gradle project, the build can fail if the SDK EULA has not been accepted. In that case, you must set the ACCEPT_MICROEJ_SDK_EULA_V3_1C environment variable to YES and restart IntelliJ IDEA. For more information about SDK EULA, refer to the Licenses chapter.

When the Gradle project is loaded, it should compile successfully, without any error. You can then learn how to launch the build of the project, or how to run it on the Simulator in the case of an Application.

Configure a Project

The SDK allows to build several types of modules. Each type has its own Gradle plugin and configuration options. Refer to the module type you want to build to configure your project:

Application Project

  • Add the com.microej.gradle.application plugin in the build.gradle.kts file:

    plugins {
        id("com.microej.gradle.application") version "1.1.0"
    }
    

    Note

    The java plugin must not be added since it is automatically applied by the MicroEJ plugin.

  • Create the Java main class in the src/main/java folder.

  • Define the property applicationEntryPoint in the microej configuration block of the build.gradle.kts file. It must be set to the Full Qualified Name of the Application main class, for example:

    microej {
      applicationEntryPoint = "com.mycompany.Main"
    }
    

Refer to the page Module Natures for a complete list of the available MicroEJ natures and their corresponding plugins.

Add-On Library Project

  • Add the com.microej.gradle.addon-library plugin in the build script:

    plugins {
        id("com.microej.gradle.addon-library") version "1.1.0"
    }
    

    Note

    The java plugin must not be added since it is automatically applied by the MicroEJ plugin.

Refer to the page Module Natures for a complete list of the available MicroEJ natures and their corresponding plugins.

Mock

  • Add the com.microej.gradle.mock plugin in the build script:

    plugins {
        id("com.microej.gradle.mock") version "1.1.0"
    }
    

    Note

    The java plugin must not be added since it is automatically applied by the MicroEJ plugin.

Refer to the VEE Porting Guide Mock chapter for how to develop a Mock.

Refer to the page Module Natures for a complete list of the available MicroEJ natures and their corresponding plugins.

Java SE Library Project

  • Add the com.microej.gradle.jse-library plugin in the build script:

    plugins {
        id("com.microej.gradle.jse-library") version "1.1.0"
    }
    

    Note

    The java plugin must not be added since it is automatically applied by the MicroEJ plugin.

Refer to the page Module Natures for a complete list of the available MicroEJ natures and their corresponding plugins.

Runtime Environment Project

  • Add the com.microej.gradle.runtime-environment plugin in the build script:

    plugins {
        id("com.microej.gradle.runtime-environment") version "1.1.0"
    }
    

    Note

    The java plugin must not be added since it is automatically applied by the MicroEJ plugin.

Refer to the page Module Natures for a complete list of the available MicroEJ natures and their corresponding plugins.

Create a subproject in an existing project

This section explains the different ways to add a module to an existing project.

Warning

If you want to add a MicroEJ module to a non MicroEJ project, for example an Android project, you must configure the repositories before creating the module. If the repositories used by your project are centralized in the settings.gradle.kts file of the project, the MicroEJ repositories defined in this file must be added to your settings.gradle.kts file.

The creation of a module with IntelliJ IDEA is done as follows:

  • Click on File > New > Module….

  • Select MicroEJ in Generators list on the left panel.

  • Fill the name of the module in the Name field.

  • Select the location of the module in the Location field.

  • Select the module type. If there is no button for your module type, click on Other button and select it in the drop-down list.

  • If you selected Application module type, you can check This is a kernel application checkbox if your Application is a Kernel.

  • Fill the version of the artifact to publish in the Version field.

  • Fill the group of the artifact to publish in the Group field.

  • Fill the name of the artifact to publish in the Artifact field.

  • Select the JVM used by Gradle in the JDK combobox.

  • Check the Add sample code checkbox.

  • Click on Create button.

Module Creation in IntelliJ IDEA

Module Creation in IntelliJ IDEA

Gradle Wrapper

It is recommended to use the Gradle Wrapper to execute a build. The Wrapper is a script that ensures that the required version of Gradle is downloaded and used during the build of a project.

When creating a project following one of the project creation systems described in the Create a Project section, the Wrapper files are automatically generated in the gradle/wrapper folder of the project. It is also possible to add the Wrapper to an existing project. This requires to install the Gradle distribution, then to execute the wrapper task with:

gradle wrapper

The Gradle version used by the project can then be updated in the gradle/wrapper/gradle-wrapper.properties file. The SDK requires Gradle 8.6 or higher:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip

To use the Wrapper during a build, use gradlew or ./gradlew depending on your OS instead of gradle in the command line:

gradlew build

In the following chapters of the documentation, the Linux command ./gradlew is used in all examples to execute a build.

Refer to the official Gradle documentation for more information about the Wrapper.