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 Android Studio is done as follows:

  • Click on File > New > Project….

  • Select Generic > New MicroEJ project.

Project Creation in Android Studio

Project Creation in Android Studio

  • Click on the Next button.

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

  • Fill the package name of the project in the Package name field.

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

  • Keep the default Android SDK in the Minimum SDK field.

  • Select Kotlin for the Build configuration language field.

Note

Groovy build script DSL is not officially supported by the SDK, so the project created by the Wizard uses Kotlin regardless of the language selected by the user.

Project Creation in Android Studio

Project Creation in Android Studio

  • Click on Next button.

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

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

  • Select the project type 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.

  • Click on Finish button.

Project Creation in Android Studio

Project Creation in Android Studio

  • Change the view from Android to Project in the selectbox at the top of the project’s files tree:

Project View in Android Studio

Project View in Android Studio

Note

If you do not use the last version of Android Studio, make sure that Gradle Wrapper uses at least Gradle version 8.6. Refer to the Gradle Wrapper section for more information.

The project created by the wizard is a multi-project with a single subproject (named app). The type of this subproject is the type that has previously been chosen.

Note

By default, Android Studio 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 Sync Now action which appears on the top-right of the editor:

Gradle Project reload in Android Studio

Gradle Project reload in Android Studio

You can also configure Android Studio 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 Android Studio. For more information about SDK EULA, refer to the Licenses chapter.

When the Gradle project has been reloaded, 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 "0.20.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 "0.20.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 "0.20.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.

Java SE Library Project

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

    plugins {
        id("com.microej.gradle.jse-library") version "0.20.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 "0.20.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 Android Studio is done as follows:

  • Click on File > New > New Module….

  • Select MicroEJ Module in Templates list on the left panel.

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

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

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

  • Select the module type 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.

  • Click on Finish button.

Module Creation in Android Studio

Module Creation in Android Studio

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.