forked from SpongePowered/Sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
458 lines (406 loc) · 16.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
import org.spongepowered.gradle.vanilla.task.DecompileJarTask
import java.util.Locale
plugins {
`maven-publish`
`java-library`
eclipse
id("org.spongepowered.gradle.vanilla")
id("com.github.johnrengelman.shadow")
id("org.spongepowered.gradle.sponge.dev") apply false // for version json generation
id("net.kyori.indra.licenser.spotless")
id("implementation-structure")
id("org.jetbrains.gradle.plugin.idea-ext")
id("com.github.ben-manes.versions")
}
val commonProject = project
val apiVersion: String by project
val minecraftVersion: String by project
val recommendedVersion: String by project
val apiAdventureVersion: String by project
val apiConfigurateVersion: String by project
val apiGsonVersion: String by project
val guavaVersion: String by project
val apiPluginSpiVersion: String by project
val asmVersion: String by project
val log4jVersion: String by project
val modlauncherVersion: String by project
val mixinVersion: String by project
val junitVersion: String by project
val mockitoVersion: String by project
val checkerVersion: 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) }
}
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 })
}
test {
useJUnitPlatform()
}
check {
dependsOn(gradle.includedBuild("SpongeAPI").task(":check"))
}
prepareWorkspace {
dependsOn(gradle.includedBuild("SpongeAPI").task(":genEventImpl"))
}
}
version = spongeImpl.generateImplementationVersionString(apiVersion, minecraftVersion, recommendedVersion)
// 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)
}
// create the sourcesets
val main by sourceSets
val applaunch by sourceSets.registering {
spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName)
project.dependencies {
mixinsConfig([email protected])
}
configurations.named(implementationConfigurationName) {
extendsFrom(applaunchConfig)
}
}
val launch by sourceSets.registering {
spongeImpl.applyNamedDependencyOnOutput(project, applaunch.get(), this, project, this.implementationConfigurationName)
project.dependencies {
mixinsConfig([email protected])
}
project.dependencies {
implementation([email protected])
}
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)
}
}
sourceSets.configureEach {
val sourceSet = this
val isMain = "main".equals(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)
}
}
dependencies {
// api
api("org.spongepowered:spongeapi:$apiVersion")
// Database stuffs... likely needs to be looked at
implementation("com.zaxxer:HikariCP:2.6.3")
implementation("org.mariadb.jdbc:mariadb-java-client:2.0.3")
implementation("com.h2database:h2:1.4.196")
implementation("org.xerial:sqlite-jdbc:3.20.0")
implementation("javax.inject:javax.inject:1")
// ASM - required for generating event listeners
implementation("org.ow2.asm:asm-util:$asmVersion")
implementation("org.ow2.asm:asm-tree:$asmVersion")
// Implementation-only Adventure
implementation(platform("net.kyori:adventure-bom:$apiAdventureVersion"))
implementation("net.kyori:adventure-serializer-configurate4")
// Launch Dependencies - Needed to bootstrap the engine(s)
launchConfig("org.spongepowered:spongeapi:$apiVersion")
launchConfig("org.spongepowered:plugin-spi:$apiPluginSpiVersion")
launchConfig("org.spongepowered:mixin:$mixinVersion")
launchConfig("org.checkerframework:checker-qual:$checkerVersion")
launchConfig("com.google.guava:guava:$guavaVersion") {
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("com.google.code.gson:gson:$apiGsonVersion")
launchConfig("org.ow2.asm:asm-tree:$asmVersion")
launchConfig("org.ow2.asm:asm-util:$asmVersion")
// Applaunch -- initialization that needs to occur without game access
applaunchConfig("org.checkerframework:checker-qual:$checkerVersion")
applaunchConfig("org.apache.logging.log4j:log4j-api:$log4jVersion")
applaunchConfig("com.google.guava:guava:$guavaVersion")
applaunchConfig(platform("org.spongepowered:configurate-bom:$apiConfigurateVersion"))
applaunchConfig("org.spongepowered:configurate-core") {
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
applaunchConfig("org.spongepowered:configurate-hocon") {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
applaunchConfig("org.spongepowered:configurate-jackson") {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
applaunchConfig("org.apache.logging.log4j:log4j-core:$log4jVersion")
applaunchConfig("org.apache.logging.log4j:log4j-jpl:$log4jVersion")
mixinsConfig(sourceSets.named("main").map { it.output })
add(mixins.get().implementationConfigurationName, "org.spongepowered:spongeapi:$apiVersion")
// Tests
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
testImplementation("org.mockito:mockito-core:$mockitoVersion")
testImplementation("org.mockito:mockito-junit-jupiter:$mockitoVersion")
testImplementation("org.mockito:mockito-inline:$mockitoVersion")
}
val organization: String by project
val projectUrl: String by project
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-patcher:build")
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.set(name.toLowerCase(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)
}
}
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
}
(this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.IdeaCompilerConfiguration::class).run {
addNotNullAssertions = false
useReleaseOption = JavaVersion.current().isJava10Compatible
parallelCompilation = true
}
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
if (JavaVersion.current() < JavaVersion.VERSION_17) {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
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(17)
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"])
}
}
}
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 ?: ""
}
}
}
}
}
}
tasks {
val jar by existing
val sourcesJar by existing
val mixinsJar by existing
val accessorsJar by existing
val launchJar by existing
val applaunchJar 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(":"))
}
}
}
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.toLowerCase()
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)
}
}
}
}
}