-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbuild.gradle.kts
276 lines (246 loc) · 8.76 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Copyright (C) 2010-2023, Danilo Pianini and contributors
* listed, for each module, in the respective subproject's build.gradle.kts file.
*
* This file is part of Alchemist, and is distributed under the terms of the
* GNU General Public License, with a linking exception,
* as described in the file LICENSE in the Alchemist distribution's top directory.
*/
import Libs.alchemist
import Libs.incarnation
import Util.allVerificationTasks
import Util.id
import Util.isInCI
import Util.isMac
import Util.isWindows
import com.github.spotbugs.snom.SpotBugsTask
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.dokka.gradle.tasks.DokkaBaseTask
import java.io.FileFilter
plugins {
id("kotlin-jvm-convention")
alias(libs.plugins.gitSemVer)
alias(libs.plugins.java.qa)
alias(libs.plugins.kotlin.qa)
alias(libs.plugins.multiJvmTesting)
alias(libs.plugins.publishOnCentral)
alias(libs.plugins.taskTree)
alias(libs.plugins.hugo)
}
val minJavaVersion: String by properties
allprojects {
with(rootProject.libs.plugins) {
apply(plugin = gitSemVer.id)
apply(plugin = java.qa.id)
apply(plugin = multiJvmTesting.id)
apply(plugin = kotlin.qa.id)
apply(plugin = publishOnCentral.id)
apply(plugin = taskTree.id)
}
multiJvm {
jvmVersionForCompilation.set(minJavaVersion.toInt())
maximumSupportedJvmVersion.set(latestJava)
if (isInCI && (isWindows || isMac)) {
/*
* Reduce time in CI by running on fewer JVMs on slower or more limited instances.
*/
testByDefaultWith(latestJava)
}
}
repositories {
google()
mavenCentral()
}
javaQA {
checkstyle {
additionalConfiguration.set(rootProject.file("checkstyle-additional-config.xml").readText())
additionalSuppressions.set(
"""
<suppress files=".*[\\/]expressions[\\/]parser[\\/].*" checks=".*"/>
<suppress files=".*[\\/]biochemistrydsl[\\/].*" checks=".*"/>
""".trimIndent(),
)
}
// TODO: enable PMD when this bug is fixed: https://github.com/pmd/pmd/issues/5096
tasks.withType<Pmd>().configureEach {
enabled = false
}
}
// TEST AND COVERAGE
tasks.withType<Test>().configureEach {
testLogging {
events("passed", "skipped", "failed", "standardError")
exceptionFormat = TestExceptionFormat.FULL
}
useJUnitPlatform()
maxHeapSize = "1g"
}
// CODE QUALITY
tasks.allVerificationTasks.configureEach {
exclude { "generated" in it.file.absolutePath }
}
tasks.withType<SpotBugsTask>().configureEach {
reports {
create("html") { enabled = true }
}
}
// PUBLISHING
tasks.withType<Javadoc>().configureEach {
// Disable Javadoc, use Dokka.
enabled = false
}
/*
* Work around:
* Task ':...:dokkaJavadoc' uses this output of task ':...:jar' without declaring an explicit or implicit dependency.
* This can lead to incorrect results being produced, depending on what order the tasks are executed.
*/
tasks.withType<AbstractDokkaTask>().configureEach {
allprojects.forEach { otherProject ->
dependsOn(otherProject.tasks.withType<org.gradle.jvm.tasks.Jar>().matching { it.name == "jar" })
}
}
if (isInCI) {
signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}
}
group = "it.unibo.alchemist"
val repoSlug = "AlchemistSimulator/Alchemist"
publishOnCentral {
projectDescription.set(extra["projectDescription"].toString())
projectLongName.set(extra["projectLongName"].toString())
projectUrl.set("https://github.com/$repoSlug")
licenseName.set("GPL 3.0 with linking exception")
licenseUrl.set(projectUrl.map { "$it/blob/master/LICENSE.md" })
scmConnection.set("git:git@github.com:$repoSlug.git")
repository("https://maven.pkg.github.com/${repoSlug.lowercase()}") {
user.set("DanySK")
password.set(System.getenv("GITHUB_TOKEN"))
}
}
publishing.publications.withType<MavenPublication>().configureEach {
pom {
developers {
developer {
name.set("Danilo Pianini")
email.set("danilo.pianini@unibo.it")
url.set("https://www.danilopianini.org")
roles.set(mutableSetOf("architect", "developer"))
}
}
}
}
}
/*
* Root project additional configuration
*/
evaluationDependsOnChildren()
dependencies {
// Depend on subprojects whose presence is necessary to run
listOf("api", "engine", "loading").forEach { api(alchemist(it)) } // Execution requirements
with(libs.apache.commons) {
implementation(io)
implementation(lang3)
}
implementation(libs.kotlin.cli)
implementation(libs.guava)
implementation(libs.logback)
testRuntimeOnly(incarnation("protelis"))
testRuntimeOnly(incarnation("sapere"))
testRuntimeOnly(incarnation("biochemistry"))
testRuntimeOnly(alchemist("cognitive-agents"))
testRuntimeOnly(alchemist("physics"))
}
tasks.matching { it.name == "kotlinStoreYarnLock" }.configureEach {
dependsOn(rootProject.tasks.named("kotlinUpgradeYarnLock"))
}
dokka {
dokkaSourceSets.register("alldocs") {
val submodules =
checkNotNull(
project.rootDir.listFiles(FileFilter { it.name.startsWith("alchemist-") }),
)
val allSourceDirs =
submodules
.asSequence()
.map { it.resolve("src") }
.onEach { check(it.isDirectory) }
.flatMap { sourceFolder ->
sourceFolder
.listFiles(FileFilter { it.name.contains("main", ignoreCase = true) })
.orEmpty()
.asSequence()
}.onEach { check(it.isDirectory) }
.flatMap { sourceSetFolder ->
sourceSetFolder
.listFiles(FileFilter { it.name in listOf("java", "kotlin") })
.orEmpty()
.asSequence()
}.toList()
sourceRoots.setFrom(allSourceDirs)
}
}
// WEBSITE
val websiteDir =
rootProject.layout.buildDirectory
.map { it.dir("website").asFile }
.get()
hugo {
version =
Regex("gohugoio/hugo@v([\\.\\-\\+\\w]+)")
.find(file("deps-utils/action.yml").readText())!!
.groups[1]!!
.value
}
fun Project.dokkaCopyTask(destination: String): Copy.() -> Unit =
{
dependsOn(tasks.withType<DokkaBaseTask>())
dependsOn(rootProject.tasks.hugoBuild)
from(
dokka.dokkaPublications.html
.get()
.outputDirectory,
)
into(File(websiteDir, "reference/$destination"))
}
val copyGlobalDokkaInTheWebsite by tasks.registering(Copy::class, dokkaCopyTask("kdoc"))
val copyModuleDokkaInTheWebsite by tasks.registering(Copy::class, alchemist("full").dokkaCopyTask("kdoc-modules"))
tasks.hugoBuild.configure {
outputDirectory = websiteDir
finalizedBy(copyGlobalDokkaInTheWebsite, copyModuleDokkaInTheWebsite)
}
val performWebsiteStringReplacements by tasks.registering {
dependsOn(copyGlobalDokkaInTheWebsite, copyModuleDokkaInTheWebsite)
doLast {
val index = File(websiteDir, "index.html")
require(index.exists()) {
"file ${index.absolutePath} has been deleted."
}
val websiteReplacements =
file("site/replacements")
.readLines()
.map { it.split("->") }
.map { it[0] to it[1] }
val replacements: List<Pair<String, String>> =
websiteReplacements + ("!development preview!" to project.version.toString())
index.parentFile
.walkTopDown()
.filter { it.isFile && it.extension.matches(Regex("html?", RegexOption.IGNORE_CASE)) }
.forEach { page ->
val initialContents = page.readText()
var text = initialContents
for ((toreplace, replacement) in replacements) {
text = text.replace(toreplace, replacement)
}
if (initialContents != text) {
page.writeText(text)
}
}
}
}
tasks.hugoBuild.configure {
finalizedBy(performWebsiteStringReplacements)
}