generated from AlchemistSimulator/alchemist-primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
106 lines (98 loc) · 4.03 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.awt.GraphicsEnvironment
/*
* DEFAULT GRADLE BUILD FOR ALCHEMIST SIMULATOR
*/
plugins {
application
alias(libs.plugins.kotlin.qa)
alias(libs.plugins.multiJvmTesting)
alias(libs.plugins.taskTree)
}
multiJvm {
jvmVersionForCompilation.set(latestJava)
}
repositories {
mavenCentral()
}
/*
* Only required if you plan to use Protelis, remove otherwise
*/
sourceSets {
main {
resources {
srcDir("src/main/protelis")
}
}
}
dependencies {
// The version and modules of Alchemist can be controlled by changing the gradle/libs.versions.toml file
implementation(libs.bundles.alchemist)
}
// Loaded from gradle.properties
val maxTime: String by project
val alchemistGroup = "Run Alchemist"
/*
* This task is used to run all experiments in sequence
*/
val runAll by tasks.register<DefaultTask>("runAll") {
group = alchemistGroup
description = "Launches all simulations"
}
/*
* Scan the folder with the simulation files, and create a task for each one of them.
*/
val isInCI = System.getenv("CI") == "true"
File(rootProject.rootDir.path + "/src/main/yaml").listFiles().orEmpty()
.filter { it.extension == "yml" } // pick all yml files in src/main/yaml
.sortedBy { it.nameWithoutExtension } // sort them, we like reproducibility
.forEach {
// one simulation file -> one gradle task
val task by tasks.register<JavaExec>("run${it.nameWithoutExtension.capitalize()}") {
group = alchemistGroup // This is for better organization when running ./gradlew tasks
description = "Launches simulation ${it.nameWithoutExtension}" // Just documentation
mainClass.set("it.unibo.alchemist.Alchemist") // The class to launch
classpath = sourceSets.main.get().runtimeClasspath // The classpath to use
// Let's use the most recent JVM
javaLauncher.set(
javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(multiJvm.latestJava)) }
)
// In case our simulation produces data, we write it in the following folder:
val exportsDir = File("${projectDir.path}/build/exports/${it.nameWithoutExtension}")
doFirst {
// this is not executed upfront, but only when the task is actually launched
// If the export folder doesn not exist, create it and its parents if needed
if (!exportsDir.exists()) {
exportsDir.mkdirs()
}
}
// These are the program arguments
args("run", it.absolutePath)
// checks if the environment is headless
if (!(GraphicsEnvironment.isHeadless() || isInCI)) {
// A graphics environment should be available, so load the effects for the UI from the "effects" folder
// Effects are expected to be named after the simulation file
args(
"--override",
"""
monitors:
type: SwingGUI
parameters:
graphics: effects/${it.nameWithoutExtension}.json
failOnHeadless: true
launcher:
parameters:
auto-start: $isInCI
""".trimIndent()
)
}
if (isInCI) {
// If it is running in a Continuous Integration environment,
// terminate the experiments after a few simulated seconds.
args("--override", "terminate: { type: AfterTime, parameters: $maxTime }")
}
// This tells gradle that this task may modify the content of the export directory
outputs.dir(exportsDir)
}
// task.dependsOn(classpathJar) // Uncomment to switch to jar-based classpath resolution
runAll.dependsOn(task)
}