Gradle Plugin for the Model API Generator

Overview

The model-api-gen.gradle.plugin is a Gradle plugin that wraps the functionality of the MPS solution for metamodel-export and Model API Generator.

API generation pipeline from MPS language to Kotlin and TypeScript

It provides an additional Gradle task which will apply a 2-staged process:

  1. MPS metamodel export to JSON (optional)

    In the first step the metamodel-export MPS solution is executed by the plugin to export the MPS structure aspect (i.e. the metamodel) to JSON files. In case your metamodel comes from another source this is an external entry point: As long as you can export your metamodel to JSON, you can use model-api-gen.

    To use JSON from another source or JSON files from a previous export, you can skip this step by simply specifying a directory, which contains the JSON files, in the configuration of the gradle task:

    metamodel {
        //...
        jsonDir = File("path/to/json/dir")
    }

    As a result, all MPS-specific configuration settings will be ignored and the specified directory will be used for the next step.

  2. JSON to model API generation

    In the second step, the previously generated JSON files containing the metamodel are being used to generate the typed API using the Kotlin/TypeScript generator in model-api-gen.

Configuration settings

Inside of the metamodel block the following settings can be configured.

Configurable Attributes

setting type description

javaExecutable

File

Location of the Java executable

moduleFolders

ArrayList<File>

Directories, that contain the language modules

mpsHome

File

Home directory of MPS

mpsHeapSize

String

MPS heap size specified as a String, e.g. "2g" for 2GB

includedLanguages

Set<String>

Set of languages, for which an API should be generated

includedLanguageNamespaces

Set<String>

Set of language namespaces, for which an API should be generated

includedConcepts

Set<String>

Set of concepts, for which an API should be generated

includedModules

Set<String>

Set of modules, for which an API should be generated

jsonDir

File

Directory containing JSON files, which represent a metamodel. Will be used as input for the generation. Specifying this will skip the export from MPS and all MPS-specific configurations will be ignored.

kotlinDir

File

Target Kotlin directory of the generator

modelqlKotlinDir

File

The generation of the ModelQL API is optional, because the output has a dependency on the ModelQL runtime. If this option is set, you have to add a dependency on org.modelix:modelql-typed.

Can be the same as kotlinDir or a directory in a separate subproject, if you run into memory issues of the Kotlin compiler.

kotlinProject

Project

Target Kotlin project of the generator

typescriptDir

File

Target TypeScript directory of the generator

registrationHelperName

String

Fully qualified name of the generated language registration helper

conceptPropertiesInterfaceName

String

Fully qualified name of the generated interface, that contains the concept meta-properties of this language set. If null (default), neither the concept meta-properties nor the corresponding interface will be generated.

taskDependencies

List<Any>

List of tasks, on which the generation process depends

Configuration Methods

method parameter type description

names

Action<NameConfig>

Block used to set a name configuration.

dependsOn

vararg Any

Adds a dependency to taskDependencies

javaExecutable

File

Sets the java executable.

modulesFrom

File

Adds a directory to `moduleFolders

includeLanguage

String

Adds the language specified by this fully qualified name to ìncludedLanguages

includeNamespace

String

Adds the namespace specified by this languagePrefix to includedNamespaces

includeConcept

String

Adds the concept specified by this fully qualified name to includedConcepts

exportModules

String

Adds the module specified by this name prefix to includedModules

Name Configuration

Inside the metamodel block a names block can be declared to configure prefix, suffix, and baseNameConversion of generated Kotlin/TypeScript elements. This is achieved by setting the attributes of the NameConfig object accordingly.

Default Values

attribute default prefix default suffix

languageClass

"L_"

""

typedNode

"N_"

""

typedNodeImpl

"_N_TypedImpl_"

""

untypedConcept

"_C_UntypedImpl_"

""

typedConcept

"C_"

""

typedConceptImpl

"_C_TypedImpl_"

""

conceptTypeAlias

"CN_"

""

Example

metamodel {
    mpsHome = file("path/to/mps/home")
    mpsHeapSize = "2g"
    kotlinDir = file("build/kotlin_gen")
    registrationHelperName = "org.modelix.Languages"
    typescriptDir = file("build/ts_gen")
    includeNamespace("jetbrains.mps.baseLanguage")
    exportModules("jetbrains.mps.runtime")
    names {
        languageClass.prefix = "MyLanguagePrefix"
        languageClass.suffix = "MyLanguageSuffix"
    }
}