Hello, Gradle!
Most Java projects use Gradle. It makes working with larger projects and dependencies easier. Likewise, MontiArc provides plugins for Gradle such that you can easily work with the tool and other libraries.
Creating a Project with Gradle
Navigate to a directory where you want to create your project. Create a new project by running:
montiarc create MyMontiArcProject
MyMontiArcProject
which contains a near-empty MontiArc Gradle project.
Inside the project open src/main/montiarc/pkg/HelloWorld.arc
:
package pkg;
import montiarc.lang.*;
component HelloWorld {
automaton {
initial state S;
S -> S / {
Console.printLn("Hello World!");
Simulation.stop();
}
}
}
The code should be familiar to you. It is the "Hello, World!" model.
The Gradle plugin expects all MontiArc sources to be inside src/main/montiarc
.
Building and running with Gradle
To set up the correct Gradle wrapper version, you can run the following once:
.\init-gradlew.bat build
./init-gradlew build
To compile the model, simply execute the Gradle build task with the now added Gradle wrapper:
.\gradlew.bat build
./gradlew build
This command generates all Java files into the build
folder of the project. You can now execute
the model, like you did before, by running:
.\gradlew.bat run -PmainClass="pkg.DeployHelloWorld"
./gradlew run -PmainClass="pkg.DeployHelloWorld"
The output should contain:
> Task :run
Hello World!