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:

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

Application Project

The required configuration elements to define for an Application Project are:

  • The Application Entry Point. It is defined by the applicationEntryPoint property 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"
    }
    

    The Project Wizards define a default value, adapt it if you change the main class of your Application.

  • The VEE to use to build and run the Application. It is defined using to the microejVee configuration in the dependencies block of the build.gradle.kts file:

    dependencies {
       microejVee("com.mycompany:vee-port:1.0.0")
    }
    

    Refer to the Select a VEE Port page to learn more about the different ways to define the VEE.

Refer to the Application Developer Guide to learn more on Applications.

Library Project

A Library project does not require any specific configuration. Refer to the Libraries and Foundation Libraries pages to learn more on Libraries.

Mock

A Mock project does not require any specific configuration. Refer to the VEE Porting Guide Mock chapter page to learn more on how to develop a Mock.

Java SE Library Project

A Java SE Library project does not require any specific configuration.

Runtime Environment Project

A Runtime Environment project does not require any specific configuration. Refer to the Runtime Environment page to learn more on how to develop a Runtime Environment.

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, and at least version 8.6 (the version 9 is not supported yet):

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.