forked from giuluck/alchemistsetup
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle.kts
99 lines (92 loc) · 3.5 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
import org.gradle.configurationcache.extensions.capitalized
/*
* DEFAULT GRADLE BUILD FOR ALCHEMIST SIMULATOR
*/
plugins {
application
alias(libs.plugins.multiJvmTesting) // Pre-configures the Java toolchains
alias(libs.plugins.taskTree) // Helps debugging dependencies among gradle tasks
}
repositories {
mavenCentral()
}
/*
* Only required if you plan to use Protelis, remove otherwise
*/
sourceSets {
main {
resources {
srcDir("src/main/protelis")
}
}
}
dependencies {
// Check the catalog at gradle/libs.versions.gradle
implementation(libs.bundles.alchemist)
}
multiJvm {
jvmVersionForCompilation.set(latestJava)
}
val batch: String by project
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.
*/
File(rootProject.rootDir.path + "/src/main/yaml").listFiles()
?.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.capitalized()}") {
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"].runtimeClasspath // The classpath to use
// Uses the latest version of java
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(multiJvm.latestJava))
},
)
// These are the program arguments
args("run", it.absolutePath, "--override")
if (System.getenv("CI") == "true" || batch == "true") {
// If it is running in a Continuous Integration environment, use the "headless" mode of the simulator
// Namely, force the simulator not to use graphical output.
args(
"""
terminate:
- type: AfterTime
parameters: $maxTime
""".trimIndent(),
)
} else {
// 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(
"""
monitors:
type: SwingGUI
parameters:
graphics: effects/${it.nameWithoutExtension}.json
""",
)
}
}
// task.dependsOn(classpathJar) // Uncomment to switch to jar-based classpath resolution
runAll.dependsOn(task)
}
tasks.withType<Tar>().configureEach {
duplicatesStrategy = DuplicatesStrategy.WARN
}
tasks.withType<Zip>().configureEach {
duplicatesStrategy = DuplicatesStrategy.WARN
}