MontiArc
This plugin generates Java code from MontiArc models.
Moreover, it distributes MontiArc models as jars with .arcsym files.
Apply it:
Within Gradle's settings script, you need to declare:
// The plugin is in the Maven repo of the chair of Software Engineering at RWTH Aachen.
// Therefore we have to make it available to our build process.
pluginManagement {
repositories {
maven {
url = uri("https://nexus.se.rwth-aachen.de/content/groups/public/")
}
}
}
// The plugin is in the Maven repo of the chair of Software Engineering at RWTH Aachen.
// Therefore we have to make it available to our build process.
pluginManagement {
repositories {
maven {
url = uri("https://nexus.se.rwth-aachen.de/content/groups/public/")
}
}
}
Then, within the build script, you need to declare:
plugins {
id("montiarc-jsim") version "VERSION_YOU_WANT_TO_USE"
}
// The generator and RTE classes are in the Maven repo of the chair of Software Engineering at RWTH Aachen
repositories {
maven {
url = uri("https://nexus.se.rwth-aachen.de/content/groups/public/")
}
}
plugins {
id "montiarc-jsim" version "VERSION_YOU_WANT_TO_USE"
}
// The generator and RTE classes are in the Maven repo of the chair of Software Engineering at RWTH Aachen
repositories {
maven {
url = uri("https://nexus.se.rwth-aachen.de/content/groups/public/")
}
}
Configure it:
The plugin adds a MontiArcCompile task for every source set that exists.
The name of that task is compileSRC_SET_NAMEMontiarc, omitting the name of the source set for the main source set.
Note that Java source files that the MontiArc generator produces are automatically added to the Java source of the same
source set. Therefore, the generated source code will automatically be compiled by compileJava (or compileTestJava,
etc. )
// Kotlin:
sourceSets {
main {
montiarc {
srcDir("where/your/montiarc/models/are") // default value: $projectDir/src/SOURCE_SET_NAME/montiarc
destinationDirectory.fileValue(file("where/to/generate/the/code/to")) // default value: $buildDir/montiarc/SOURCE_SET_NAME
}
}
}
// Declare dependencies on published models
dependencies {
montiarc("some.model.publisher:logic-gates:1.2.0")
cd2pojo4montiarc("some.class:diagram.types:1.1.0")
testMontiarc("some.testModel.publisher:logic-gates:1.2.0")
}
task.compileMontiarc { // compile task for other sourceSets: "compile{SRC_SET_NAME}Montiarc"
symbolImportDir.from("${projectDir}/src/SRC_SET_NAME/more_symbols")
useClass2Mc.set(true) // Default value is false
}
sourceSets {
main {
montiarc {
srcDir "where/your/montiarc/models/are" // default value: $projectDir/src/SOURCE_SET_NAME/montiarc
destinationDirectory.fileValue(file("where/to/generate/the/code/to")) // default value: $buildDir/montiarc/SOURCE_SET_NAME
}
}
}
// Declare dependencies on published models
dependencies {
montiarc "some.model.publisher:logic-gates:1.2.0"
cd2pojo4montiarc "some.class:diagram.types:1.1.0"
testMontiarc "some.testModel.publisher:logic-gates:1.2.0"
}
task.compileMontiarc { // compile task for other sourceSets: "compile{SRC_SET_NAME}Montiarc"
symbolImportDir.from("${projectDir}/src/SRC_SET_NAME/more_symbols")
useClass2Mc.set(true) // Default value is false
}
Note that the generated java code will be generated to $destinationDirectory/java and created .arcsym files are
placed in $destinationDirectory/symbols (destinationDirectory being defined in the montiarc entry of the source
set).
Configuration options in detail:
Each MontiArcCompile task has the following configuration options that can be set. Some configuration options only have default values, if the task is created for a source set.
| Option | Default value | Description |
|---|---|---|
| modelPath | $projectDir/src/SOURCE_SET_NAME/montiarc |
Where to find the MontiArc models for which Java code should be generated. You can specify multiple locations with multiple modelPath.from(...) statements. |
| hwcPath | All java code from the same source set (main, or test, etc.) | Where to find the handwritten code extensions for the generated MontiArc code. |
| symbolImportDir | The montiarcSymbolDependencies configuration |
If you want to use .sym files, then you can use this configuration parameter to inform the generator where to find them. You can specify multiple locations with multiple symbolImportDir.from(...) statements. |
| useClass2Mc | false |
If you want to use java types (or other JVM types) in your MontiArc models, then you set this configuration parameter to true. By this, all JVM types that are on the class path of the generator (which is the configuration maGenerator) will be accessible from MontiArc models. Note: this will be changed in the future. |
| outputDir | $buildDir/montiarc/SOURCE_SET_NAME |
Where the generated files should be placed. Generated Java code ist placed in the java subfolder, exported symbol files are put in the symbols subfolder. |
Interplay with cd2pojo
If the cd2pojo plugin Plugin is also applied, then the class diagram models defined therein
are also available in the MontiArc models of the same source set.
Added build elements
- The Plugin adds the dependency configuration maGenerator on which it places the dependency on the generator that is
used to generate .java code from the .arc files. If you use
class2mc, then you can place the java classes that you want to use in your models on this configuration. - For every SourceSet, the plugin
- Adds a
MontiarcCompiletask that performs the generation step from .arc models to .java code. The task name iscompileMontiarcfor main andcompileSourceSetNameMontiarcfor others - Adds a jar task packaging the .arcsym models of the main source set, adding it to the default publication.
- Adds three configurations:
montiarcfor the main source set andsourceSetNameMontiarcfor others:\ Used to declare dependencies on other MontiArc models. This configuration is not resolvable or consumable and only serves the purpose to declare dependencies. The models of the dependencies will automatically be added to thecompileMontiarctask and their java implementations will automatically be added to theimplementationconfiguration for compilation and runtime.cd4pojo4montiarcfor the main source set andsourceSetNameCd2pojo4montiarcfor others:\ Used to declare dependencies of MontiArc models on other class diagram projects. This configuration is not resolvable or consumable and only serves the purpose to declare dependencies. The models of the dependencies will automatically be added to thecompileMontiarctask and their java implementations will automatically be added to theimplementationconfiguration for compilation and runtime.montiarcSymbolDependenciesfor the main source set andsourceSetNameMontiarcSymbolDependenciesfor others:\ Loads the MontiArc dependencies (represented by .arcsym files). Do not use this configuration to declare the dependencies (usemontiarcfor this purpose instead), but use this configuration, when you want to access the MontiArc models of the dependencies. (This configuration is automatically derived from themontiarcconfiguration, only considering the montiarc models.)cd2pojo4montiarcSymbolDependenciesfor the main source set andsourceSetNameCd2pojo4montiarcSymbolDependenciesfor others:\ Loads the class diagram dependencies of our MontiArc models (represented by .cdsym files). Do not use this configuration to declare the dependencies (usecd2pojo4montiarcfor this purpose instead), but use this configuration, when you want to access the class diagram dependencies. (This configuration is automatically derived from thecd2pojo4montiarcconfiguration, only considering the class diagram models.)montiarcSymbolElementsfor the main source set andsourceSetNameMontiarcSymbolElementsfor others:\ Contains the jar of the MontiArc models (represented by .arcsym files) that is added to the default publication set. Is also used to publish the list of MontiArc dependencies of this project. To this end, it extends themontiarcconfiguration. By default, this configuration is only added for the main source set.cd2pojo4montiarcSymbolDependencyElementsfor the main source set andsourceSetNameCd2pojo4montiarcSymbolDependencyElementsfor others:\ Used to publish the list of class diagram dependencies of our MontiArc models. To this end, it extends thecd2pojo4montiarcconfiguration. By default, this configuration is only added for the main source set. If the project also applies thecd2pojoplugin, then the cd-symbols jar is also published with this configuration. This is due to technical reasons.
- Models declared in the main source set are also available in the test source sets.
Fixing problems:
- The generator only generates classes with a TOP postfix\ When you use the default value of the hwcPath, the outputDir may erroneously be in the hwcPath because filtering the outputDir went wrong. In this case, the generator thinks that the previously generated files are handwritten extensions. To fix this, you should set the hwcPath manually. This will overwrite the default value, including the entry with the outputDir.
- There is no main or test source set\ These source sets only exist if the java plugin is applied. If only the java-base plugin is applied, then there are no main or tests source sets.
- If your dependencies use class2mc, then you have to activate it for your own project, too.
- If you activate class2mc for your main source set, you also have to activate it for your test source set.