-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
build.gradle.kts
502 lines (443 loc) · 17.6 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
import org.spongepowered.gradle.vanilla.task.DecompileJarTask
import java.util.Locale
plugins {
`maven-publish`
`java-library`
eclipse
id("org.spongepowered.gradle.vanilla")
alias(libs.plugins.shadow)
alias(apiLibs.plugins.spongeGradle.convention) apply false // for version json generation
alias(libs.plugins.indra.licenserSpotless) version apiLibs.versions.indra.get()
id("implementation-structure")
id(apiLibs.plugins.ideaExt.get().pluginId)
alias(libs.plugins.versions)
}
val commonProject = project
val apiVersion: String by project
val apiJavaTarget: String by project
val minecraftVersion: String by project
val recommendedVersion: String by project
val organization: String by project
val projectUrl: String by project
val commonManifest = java.manifest {
attributes(
"Specification-Title" to "Sponge",
"Specification-Vendor" to "SpongePowered",
"Specification-Version" to apiVersion,
"Implementation-Title" to project.name,
"Implementation-Version" to spongeImpl.generateImplementationVersionString(apiVersion, minecraftVersion, recommendedVersion),
"Implementation-Vendor" to "SpongePowered"
)
// These two are included by most CI's
System.getenv()["GIT_COMMIT"]?.apply { attributes("Git-Commit" to this) }
System.getenv()["GIT_BRANCH"]?.apply { attributes("Git-Branch" to this) }
}
version = spongeImpl.generateImplementationVersionString(apiVersion, minecraftVersion, recommendedVersion)
// SpongeCommon configurations
val applaunchConfig by configurations.register("applaunch")
val launchConfig by configurations.register("launch") {
extendsFrom(configurations.minecraft.get())
extendsFrom(applaunchConfig)
}
val accessorsConfig by configurations.register("accessors") {
extendsFrom(launchConfig)
}
val mixinsConfig by configurations.register("mixins") {
extendsFrom(applaunchConfig)
extendsFrom(launchConfig)
}
// SpongeCommon source sets
val main by sourceSets
val applaunch by sourceSets.registering {
spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName)
configurations.named(implementationConfigurationName) {
extendsFrom(applaunchConfig)
}
}
val launch by sourceSets.registering {
spongeImpl.applyNamedDependencyOnOutput(project, applaunch.get(), this, project, this.implementationConfigurationName)
spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName)
configurations.named(implementationConfigurationName) {
extendsFrom(launchConfig)
}
}
val accessors by sourceSets.registering {
spongeImpl.applyNamedDependencyOnOutput(project, launch.get(), this, project, this.implementationConfigurationName)
spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName)
configurations.named(implementationConfigurationName) {
extendsFrom(accessorsConfig)
}
}
val mixins by sourceSets.registering {
spongeImpl.applyNamedDependencyOnOutput(project, launch.get(), this, project, this.implementationConfigurationName)
spongeImpl.applyNamedDependencyOnOutput(project, applaunch.get(), this, project, this.implementationConfigurationName)
spongeImpl.applyNamedDependencyOnOutput(project, accessors.get(), this, project, this.implementationConfigurationName)
spongeImpl.applyNamedDependencyOnOutput(project, main, this, project, this.implementationConfigurationName)
configurations.named(implementationConfigurationName) {
extendsFrom(mixinsConfig)
}
}
dependencies {
// api
api("org.spongepowered:spongeapi:$apiVersion")
implementation(libs.javaxInject)
// ASM - required for generating event listeners
implementation(libs.asm.util)
implementation(libs.asm.tree)
// Implementation-only Adventure
implementation(platform(apiLibs.adventure.bom)) {
exclude(group = "org.jetbrains", module = "annotations")
}
implementation(libs.adventure.serializerConfigurate4) {
exclude(group = "org.jetbrains", module = "annotations")
exclude(group = "org.checkerframework", module = "checker-qual")
}
implementation(libs.adventure.serializerAnsi) {
exclude(group = "org.jetbrains", module = "annotations")
exclude(group = "org.checkerframework", module = "checker-qual")
}
// Launch Dependencies - Needed to bootstrap the engine(s)
launchConfig("org.spongepowered:spongeapi:$apiVersion")
launchConfig(apiLibs.pluginSpi) {
exclude(group = "org.checkerframework", module = "checker-qual")
exclude(group = "com.google.code.gson", module = "gson")
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
exclude(group = "org.apache.commons", module = "commons-lang3")
}
launchConfig(libs.mixin)
launchConfig(apiLibs.checkerQual)
launchConfig(libs.guava) {
exclude(group = "com.google.code.findbugs", module = "jsr305") // We don't want to use jsr305, use checkerframework
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
exclude(group = "com.google.j2objc", module = "j2objc-annotations")
exclude(group = "org.codehaus.mojo", module = "animal-sniffer-annotations")
exclude(group = "com.google.errorprone", module = "error_prone_annotations")
}
launchConfig(apiLibs.gson)
launchConfig(libs.asm.tree)
launchConfig(libs.asm.util)
// Applaunch -- initialization that needs to occur without game access
applaunchConfig(apiLibs.checkerQual)
applaunchConfig(libs.log4j.api)
applaunchConfig(libs.guava) {
exclude(group = "com.google.errorprone", module = "error_prone_annotations")
exclude(group = "org.checkerframework", module = "checker-qual")
}
applaunchConfig(platform(apiLibs.configurate.bom))
applaunchConfig(apiLibs.configurate.core) {
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
applaunchConfig(apiLibs.configurate.hocon) {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
applaunchConfig(libs.configurate.jackson) {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
applaunchConfig(libs.log4j.core)
applaunchConfig(libs.log4j.jpl)
applaunchConfig(apiLibs.pluginSpi) {
exclude(group = "org.checkerframework", module = "checker-qual")
exclude(group = "com.google.code.gson", module = "gson")
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
}
add(mixins.get().implementationConfigurationName, "org.spongepowered:spongeapi:$apiVersion")
// Tests
testImplementation(platform(apiLibs.junit.bom))
testImplementation(apiLibs.junit.api)
testImplementation(apiLibs.junit.params)
testRuntimeOnly(apiLibs.junit.engine)
testRuntimeOnly(apiLibs.junit.launcher)
testImplementation(libs.mockito.core)
testImplementation(libs.mockito.junitJupiter) {
exclude(group = "org.junit.jupiter", module = "junit-jupiter-api")
}
}
indraSpotlessLicenser {
licenseHeaderFile(rootProject.file("HEADER.txt"))
property("name", "Sponge")
property("organization", organization)
property("url", projectUrl)
}
idea {
if (project != null) {
(project as ExtensionAware).extensions["settings"].run {
(this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.TaskTriggersConfig::class).run {
afterSync(":modlauncher-transformers:build")
}
}
}
}
allprojects {
configurations.configureEach {
resolutionStrategy.dependencySubstitution {
// https://github.com/zml2008/guice/tree/backport/5.0.1
substitute(module("com.google.inject:guice:5.0.1"))
.because("We need to run against Guava 21")
.using(module("ca.stellardrift.guice-backport:guice:5.0.1"))
}
}
apply(plugin = "org.jetbrains.gradle.plugin.idea-ext")
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "net.kyori.indra.licenser.spotless")
base {
archivesName = name.lowercase(Locale.ENGLISH)
}
plugins.withId("org.spongepowered.gradle.vanilla") {
minecraft {
version(minecraftVersion)
injectRepositories(false)
project.sourceSets["main"].resources
.filter { it.name.endsWith(".accesswidener") }
.files
.forEach {
accessWideners(it)
parent?.minecraft?.accessWideners(it)
}
}
dependencies {
decompiler(libs.vineflower)
}
tasks.named("decompile", DecompileJarTask::class) {
extraFernFlowerArgs.put("win", "0")
}
}
idea {
if (project != null) {
(project as ExtensionAware).extensions["settings"].run {
(this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.ActionDelegationConfig::class).run {
delegateBuildRunToGradle = false
testRunner = org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.PLATFORM
}
extensions.getByType(org.jetbrains.gradle.ext.IdeaCompilerConfiguration::class).run {
addNotNullAssertions = false
useReleaseOption = JavaVersion.current().isJava10Compatible
parallelCompilation = true
}
}
}
}
java {
val targetJavaVersion = JavaVersion.toVersion(apiJavaTarget.toInt())
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion
if (JavaVersion.current() < targetJavaVersion) {
toolchain {
languageVersion.set(JavaLanguageVersion.of(apiJavaTarget.toInt()))
}
}
}
tasks.withType<AbstractArchiveTask> {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
spotless {
java {
toggleOffOn("@formatter:off", "@formatter:on")
endWithNewline()
indentWithSpaces(4)
trimTrailingWhitespace()
removeUnusedImports()
importOrderFile(rootProject.file("SpongeAPI/extra/eclipse/sponge_eclipse.importorder"))
targetExclude("build/generated/**/*") // exclude generated content
}
kotlinGradle {
endWithNewline()
indentWithSpaces(4)
trimTrailingWhitespace()
}
}
val spongeSnapshotRepo: String? by project
val spongeReleaseRepo: String? by project
tasks {
val emptyAnnotationProcessors = objects.fileCollection()
withType(JavaCompile::class).configureEach {
options.compilerArgs.addAll(listOf("-Xmaxerrs", "1000"))
options.encoding = "UTF-8"
options.release.set(apiJavaTarget.toInt())
if (project.name != "testplugins" && System.getProperty("idea.sync.active") != null) {
options.annotationProcessorPath = emptyAnnotationProcessors // hack so IntelliJ doesn't try to run Mixin AP
}
}
withType(PublishToMavenRepository::class).configureEach {
onlyIf {
(repository == publishing.repositories["GitHubPackages"] &&
!(rootProject.version as String).endsWith("-SNAPSHOT")) ||
(!spongeSnapshotRepo.isNullOrBlank()
&& !spongeReleaseRepo.isNullOrBlank()
&& repository == publishing.repositories["spongeRepo"]
&& publication == publishing.publications["sponge"])
}
}
}
sourceSets.configureEach {
val sourceSet = this
val isMain = "main" == sourceSet.name
val sourcesJarName: String = if (isMain) "sourcesJar" else (sourceSet.name + "SourcesJar")
tasks.register(sourcesJarName, Jar::class.java) {
group = "build"
val classifier = if (isMain) "sources" else (sourceSet.name + "-sources")
archiveClassifier.set(classifier)
from(sourceSet.allJava)
}
}
tasks.register("printConfigsHierarchy") {
group = "debug"
doLast {
configurations.forEach { conf: Configuration ->
val seen = mutableSetOf<Configuration>()
println("Parents of ${conf.name}:")
printParents(conf, "", seen)
}
}
}
tasks.register("printConfigsResolution") {
group = "debug"
doLast {
configurations.forEach { conf: Configuration ->
println()
println("Artifacts of ${conf.name}:")
if (conf.isCanBeResolved) {
try {
conf.forEach {
println(it)
}
} catch (e: Exception) {
println("error")
}
} else {
println("not resolved")
}
}
}
}
afterEvaluate {
publishing {
repositories {
maven {
name = "GitHubPackages"
this.url = uri("https://maven.pkg.github.com/SpongePowered/${rootProject.name}")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
// Set by the build server
maven {
name = "spongeRepo"
val repoUrl = if ((version as String).endsWith("-SNAPSHOT")) spongeSnapshotRepo else spongeReleaseRepo
repoUrl?.apply {
url = uri(this)
}
val spongeUsername: String? by project
val spongePassword: String? by project
credentials {
username = spongeUsername ?: ""
password = spongePassword ?: ""
}
}
}
}
}
}
fun printParents(conf: Configuration, indent: String, seen: MutableSet<Configuration>) {
for (parent in conf.extendsFrom) {
if (parent in seen) {
continue
}
seen.add(parent)
println("$indent - ${parent.name}")
printParents(parent, indent + " ", seen)
}
}
tasks {
jar {
manifest.from(commonManifest)
}
val mixinsJar by registering(Jar::class) {
archiveClassifier.set("mixins")
manifest.from(commonManifest)
from(mixins.map { it.output })
}
val accessorsJar by registering(Jar::class) {
archiveClassifier.set("accessors")
manifest.from(commonManifest)
from(accessors.map { it.output })
}
val launchJar by registering(Jar::class) {
archiveClassifier.set("launch")
manifest.from(commonManifest)
from(launch.map { it.output })
}
val applaunchJar by registering(Jar::class) {
archiveClassifier.set("applaunch")
manifest.from(commonManifest)
from(applaunch.map { it.output })
}
val jar by existing
val sourcesJar by existing
shadowJar {
mergeServiceFiles()
archiveClassifier.set("dev")
manifest {
attributes(mapOf(
"Access-Widener" to "common.accesswidener",
"Multi-Release" to true
))
from(commonManifest)
}
from(jar)
from(sourcesJar)
from(mixinsJar)
from(accessorsJar)
from(launchJar)
from(applaunchJar)
dependencies {
include(project(":"))
}
}
test {
useJUnitPlatform()
}
check {
dependsOn(gradle.includedBuild("SpongeAPI").task(":check"))
}
prepareWorkspace {
dependsOn(gradle.includedBuild("SpongeAPI").task(":genEventImpl"))
}
}
publishing {
publications {
register("sponge", MavenPublication::class) {
from(components["java"])
artifact(tasks["sourcesJar"])
artifact(tasks["mixinsJar"])
artifact(tasks["mixinsSourcesJar"])
artifact(tasks["accessorsJar"])
artifact(tasks["accessorsSourcesJar"])
artifact(tasks["launchJar"])
artifact(tasks["launchSourcesJar"])
artifact(tasks["applaunchJar"])
artifact(tasks["applaunchSourcesJar"])
pom {
artifactId = project.name.lowercase()
this.name.set(project.name)
this.description.set(project.description)
this.url.set(projectUrl)
licenses {
license {
this.name.set("MIT")
this.url.set("https://opensource.org/licenses/MIT")
}
}
scm {
connection.set("scm:git:git://github.com/SpongePowered/Sponge.git")
developerConnection.set("scm:git:ssh://github.com/SpongePowered/Sponge.git")
this.url.set(projectUrl)
}
}
}
}
}