This document is about how to integrate the eTrice generators with Gradle. For an introduction to general concepts see the Gradle User Guide. The user guide also explains how to build Java/C/C++ software with Gradle. Keep in mind that the plugins require at least Gradle 6.9.
Getting Started
In order to use one of the provided Gradle plugins and tasks the plugin must be listed in the plugins block of your build file. Further there must be a repository declared to resolve dependencies from, e.g. eTrice generator, modellib, runtime.
repositories {
maven {
url "https://repo.eclipse.org/content/repositories/maven_central/"
}
maven {
url "https://repo.eclipse.org/content/repositories/etrice/"
}
}
For more detailed information about all provided classes also see the generated javadoc. |
Plugins
eTrice Base Plugin
This plugin sets up the build to generate code from model files.
Use the provided generator
configuration to declare the dependencies of the generators that you want to use and the modelpath
configuration to declare model dependencies.
Define model sources in the modelSet
extension container.
A model source contains the source directories of your model files and the settings for the generator to use.
For every model source a generate task is created to generate code from the specified model files.
Additionally the eclipseModelpath
task is configured to create a suitable Eclipse modelpath file.
Also the adhoc
component is created for publishing a zip containing all model files of this project.
plugins {
id "de.protos.etrice-base" version "2.3.2"
}
dependencies {
// add the dependency of the generator
generator "org.eclipse.etrice:org.eclipse.etrice.generator.c:3.2.0"
// add a project dependency of the model
modelpath project(":runtime:org.eclipse.etrice.modellib.c")
}
modelSet {
// Define a model source
room {
source.srcDir "model"
source.include "**/*.room", "**/*.etmap", "**/*.etphys"
module = "etrice-c"
genDir = layout.buildDirectory.dir("src-gen/room")
option "msc_instr"
}
}
eTrice C Plugin
This plugin applies the model base plugin and sets up the room
model source configured with the eTrice C generator.
By default all room files in the 'model' directory of your project are passed to the generator.
The target directory for the generated code is 'build/src-gen/room'.
plugins {
id "de.protos.etrice-c" version "2.3.2"
}
dependencies {
generator "org.eclipse.etrice:org.eclipse.etrice.generator.c:3.2.0"
}
Model Library Plugin
A plugin for downloading and extracting model zips produced by the eTrice base plugin.
Use the modelLibrary
configuration to declare the model projects to download.
The unzipModel
task is set up to extract the model zips into the target directory 'build/modellib'.
plugins {
id "de.protos.model-library" version "2.3.2"
}
dependencies {
modelLibrary "org.eclipse.etrice:org.eclipse.etrice.modellib.c:3.2.0"
}
Source Publish Plugin
This plugin configures the adhoc
component to contain the source zip produced by the zipSource
task.
plugins {
id "maven-publish"
id "de.protos.source-publish" version "2.3.2"
}
zipSource.from "src"
publishing {
publications {
runtime(MavenPublication) {
from components.adhoc
}
}
}
Source Library Plugin
This plugin downloads and extracts source zips produced by the source publish plugin.
Declare the modules to download in the sourceLibrary
configuration.
The unzipSource
task is configured to extract the source into 'build/sourcelib'.
plugins {
id "de.protos.source-library" version "2.3.2"
}
dependencies {
sourceLibrary "org.eclipse.etrice:org.eclipse.etrice.runtime.c:3.2.0"
}
EtUnit Convert Plugin
This plugin allows to define etunit convert tasks in the etunitConvert
extension.
The etunitConverter
configuration can be used to specify the classpath of the etunit converter.
plugins {
id "de.protos.etunit-convert" version "2.3.2"
}
dependencies {
etunitConverter "org.eclipse.etrice:org.eclipse.etrice.etunit.converter:3.2.0"
}
etunitConvert {
convertTestResults {
source "log"
options.addAll "-suite", "my.suite.name"
}
}
Tasks
Generate Task
Generator module
Use the module
property to specify the generator variant by its symbolic name.
The symbolic name is specified by a file with the name of the generator in the resource location 'META-INF/generators' that contains the fully qualified name of the generator module class. |
-
etrice-c
,etrice-cpp
,etrice-java
,etrice-doc
-
cage
-
etex-c
,etex-java
,etex-doc
Generator input files
The model files that are passed to the generator are configured using the inherited methods from SourceTask
.
You can add files using the source
method and specify include and exclude patterns.
source "src/main/room", "src/main/etmap"
exclude "**/diagrams/"
include "**/*.room", "**/*.etmap"
Generator output directory
The target directory for the generated source files can be set via the genDir
property.
Generator modelpath
The modelpath
property specifies the directories that are searched by the generator for referenced models.
Generator options
Generator options are stored as key value pairs in the options
map property, except for the target directory and the modelpath.
These are specified in the corresponding properties above.
Generator classpath
The generator classpath contains the dependencies of the generator itself and can be set with the classpath
property.
All generator classes are resolved and loaded at runtime.
Try to use the same classpath for all your generate tasks. This allows reusing the worker processes and therefore speeding up the build process significantly while reducing its memory footprint. |
Eclipse Modelpath Task
This task type generates an eclipse modelpath file.
Use the srcDirs
and projects
properties to influence the generated modelpath file.
Executing this task will overwrite existing eclipse modelpath files. |
Unzip Task
Syncs files from zip archives into a directory.
EtUnit Convert Task
Converts etunit files to xml test reports.
Complete Example
The Gradle buildscript below downloads the eTrice C generator, modellib and runtime and compiles the generated source code for Windows.
plugins {
id "c"
id "de.protos.etrice-c" version "2.3.2"
id "de.protos.model-library" version "2.3.2"
id "de.protos.source-library" version "2.3.2"
}
repositories {
maven {
url "https://repo.eclipse.org/content/repositories/maven_central/"
}
maven {
url "https://repo.eclipse.org/content/repositories/etrice/"
}
}
dependencies {
generator "org.eclipse.etrice:org.eclipse.etrice.generator.c:3.2.0"
modelLibrary "org.eclipse.etrice:org.eclipse.etrice.modellib.c:3.2.0"
sourceLibrary "org.eclipse.etrice:org.eclipse.etrice.runtime.c:3.2.0"
sourceLibrary "org.eclipse.etrice:org.eclipse.etrice.runtime.c.mt-win-mingw:3.2.0"
}
modelSet {
room {
source.srcDirs "model", unzipModel.destination
source.include "**/*.room", "**/*.etmap", "**/*.etphys"
module = "etrice-c"
option "msc_instr"
}
}
model {
components {
main(NativeExecutableSpec) {
sources {
c {
source {
srcDirs = [generateRoom.genDir, unzipSource.destination]
include "**/*.c"
}
exportedHeaders {
srcDirs = [generateRoom.genDir, unzipSource.destination]
}
builtBy generateRoom, unzipSource
}
}
binaries.all {
cCompiler.args "-g3", "-O0"
linker.args "-lws2_32"
}
}
}
}