Gradle Plugin for the Model API Generator
API doc | Repository | buildfile | Artifacts: Nexus GitHub Packages |
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.
It provides an additional Gradle task which will apply a 2-staged process:
-
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.
-
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 |
---|---|---|
|
File |
Location of the Java executable |
|
ArrayList<File> |
Directories, that contain the language modules |
|
File |
Home directory of MPS |
|
String |
MPS heap size specified as a String, e.g. "2g" for 2GB |
|
Set<String> |
Set of languages, for which an API should be generated |
|
Set<String> |
Set of language namespaces, for which an API should be generated |
|
Set<String> |
Set of concepts, for which an API should be generated |
|
Set<String> |
Set of modules, for which an API should be generated |
|
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. |
|
File |
Target Kotlin directory of the generator |
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 Can be the same as |
|
|
Project |
Target Kotlin project of the generator |
|
File |
Target TypeScript directory of the generator |
|
String |
Fully qualified name of the generated language registration helper |
|
String |
Fully qualified name of the generated interface, that contains the concept meta-properties of this language set.
If |
|
List<Any> |
List of tasks, on which the generation process depends |
Configuration Methods
method | parameter type | description |
---|---|---|
|
Action<NameConfig> |
Block used to set a name configuration. |
|
vararg Any |
Adds a dependency to |
|
File |
Sets the java executable. |
|
File |
Adds a directory to `moduleFolders |
|
String |
Adds the language specified by this fully qualified name to |
|
String |
Adds the namespace specified by this languagePrefix to |
|
String |
Adds the concept specified by this fully qualified name to |
|
String |
Adds the module specified by this name prefix to |
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"
}
}