forked from FabricMC/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
683 lines (558 loc) · 17.2 KB
/
build.gradle
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.135'
}
}
plugins {
id "java-library"
id "eclipse"
id "idea"
id "maven-publish"
id 'jacoco'
id "fabric-loom" version "1.0.12" apply false
id "com.diffplug.spotless" version "6.11.0"
id "org.ajoberstar.grgit" version "3.1.0"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "2.4.3"
id "me.modmuss50.remotesign" version "0.3.0" apply false
}
def ENV = System.getenv()
def signingEnabled = ENV.SIGNING_SERVER
version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch()
logger.lifecycle("Building Fabric: " + version)
import org.apache.commons.codec.digest.DigestUtils
def getSubprojectVersion(project) {
// Get the version from the gradle.properties file
def version = project.properties["${project.name}-version"]
if (!version) {
throw new NullPointerException("Could not find version for " + project.name)
}
if (grgit == null) {
return version + "+nogit"
}
def latestCommits = grgit.log(paths: [project.name], maxCommits: 1)
if (latestCommits.isEmpty()) {
return version + "+uncommited"
}
return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2)
}
def getBranch() {
def ENV = System.getenv()
if (ENV.GITHUB_REF) {
def branch = ENV.GITHUB_REF
return branch.substring(branch.lastIndexOf("/") + 1)
}
if (grgit == null) {
return "unknown"
}
def branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
def moduleDependencies(project, List<String> depNames) {
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') }
def clientOutputs = depNames.iterator().collect { findProject(":$it").sourceSets.client.output }
project.dependencies {
deps.each {
api it
}
clientOutputs.each {
clientImplementation it
}
}
// As we manually handle the maven artifacts, we need to also manually specify the deps.
project.publishing {
publications {
mavenJava(MavenPublication) {
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
deps.each {
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}
}
def testDependencies(project, List<String> depNames) {
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') }
def clientOutputs = depNames.iterator().collect { findProject(":$it").sourceSets.client.output }
project.dependencies {
deps.each {
testmodImplementation it
}
clientOutputs.each {
testmodImplementation it
}
}
}
allprojects {
group = "net.fabricmc.fabric-api"
apply plugin: "maven-publish"
apply plugin: "me.modmuss50.remotesign"
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
if (signingEnabled) {
remoteSign {
requestUrl = ENV.SIGNING_SERVER
pgpAuthKey = ENV.SIGNING_PGP_KEY
jarAuthKey = ENV.SIGNING_JAR_KEY
afterEvaluate {
// PGP sign all maven publications.
sign publishing.publications.mavenJava
}
}
}
publishing {
setupRepositories(repositories)
}
if (it.name == "deprecated") return
apply plugin: "java-library"
apply plugin: "checkstyle"
apply plugin: "fabric-loom"
apply plugin: "com.diffplug.spotless"
tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}
java {
// Must be added before the split source sets are setup.
withSourcesJar()
}
loom {
splitEnvironmentSourceSets()
}
sourceSets {
testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += client.compileClasspath
runtimeClasspath += client.runtimeClasspath
}
}
loom {
runtimeOnlyLog4j = true
runs {
testmodClient {
client()
ideConfigGenerated project.rootProject == project
name = "Testmod Client"
source sourceSets.testmod
}
testmodServer {
server()
ideConfigGenerated project.rootProject == project
name = "Testmod Server"
source sourceSets.testmod
}
}
}
allprojects.each { p ->
if (project.name == "deprecated") return
loom.mods.register(p.name) {
sourceSet p.sourceSets.main
sourceSet p.sourceSets.client
}
loom.mods.register(p.name + "-testmod") {
sourceSet p.sourceSets.testmod
}
}
dependencies {
minecraft "com.mojang:minecraft:$rootProject.minecraft_version"
mappings "net.fabricmc:yarn:${rootProject.minecraft_version}${project.yarn_version}:v2"
modApi "net.fabricmc:fabric-loader:${project.loader_version}"
testmodImplementation sourceSets.main.output
testmodImplementation sourceSets.client.output
}
tasks.withType(ProcessResources).configureEach {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER"))
}
}
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "10.3.3"
}
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
if (signingEnabled) {
remoteSign {
sign remapJar
}
}
// Run this task after updating minecraft to regenerate any required resources
task generateResources {
group = "fabric"
}
task testmodJar(type: Jar) {
from sourceSets.testmod.output
destinationDirectory = new File(project.buildDir, "devlibs")
archiveClassifier = "testmod"
}
[jar, sourcesJar].each {
it.from(rootProject.file("LICENSE")) {
rename { "${it}-${project.archivesBaseName}"}
}
}
if (file("src/client").exists() && !file("src/main").exists()) {
remapJar {
additionalClientOnlyEntries.add("LICENSE-${project.archivesBaseName}")
}
remapSourcesJar {
additionalClientOnlyEntries.add("LICENSE-${project.archivesBaseName}")
}
}
task remapTestmodJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: testmodJar) {
input = testmodJar.archiveFile
archiveClassifier = "testmod"
addNestedDependencies = false
}
build.dependsOn remapTestmodJar
task validateMixinNames(type: net.fabricmc.loom.task.ValidateMixinNameTask) {
source(sourceSets.main.output)
source(sourceSets.client.output)
source(sourceSets.testmod.output)
}
// Apply to each valid subproject.
apply from: rootProject.file('gradle/package-info.gradle')
}
remapTestmodJar {
def testModJarTasks = []
subprojects {
if (it.name == "deprecated" || !it.file("src/testmod").exists()) return
testModJarTasks += it.tasks.remapTestmodJar
}
nestedJars.setFrom(testModJarTasks)
addNestedDependencies = true
}
// Apply auxiliary buildscripts to submodules
// This must be done after all plugins are applied to subprojects
apply from: "gradle/module-validation.gradle"
apply from: "gradle/module-versioning.gradle"
loom {
// Required as the item-group API uses access widened classes in its API, without this the javadoc generation fails.
accessWidenerPath = file("fabric-item-group-api-v1/src/main/resources/fabric-item-group-api-v1.accesswidener")
}
javadoc {
options {
source = "17"
encoding = "UTF-8"
charSet = "UTF-8"
memberLevel = JavadocMemberLevel.PACKAGE
links(
"https://guava.dev/releases/31.1-jre/api/docs/",
"https://asm.ow2.io/javadoc/",
"https://docs.oracle.com/en/java/javase/17/docs/api/",
"https://jenkins.liteloader.com/job/Mixin/javadoc/",
"https://logging.apache.org/log4j/2.x/log4j-api/apidocs/",
"https://www.slf4j.org/apidocs/",
"https://netty.io/4.1/api/",
"https://javadoc.lwjgl.org/",
"https://www.javadoc.io/doc/com.google.code.gson/gson/2.10/",
"https://javadoc.io/doc/org.jetbrains/annotations/latest/",
"https://javadoc.io/doc/it.unimi.dsi/fastutil/",
"https://javadoc.scijava.org/JOML/",
"https://maven.fabricmc.net/docs/yarn-${rootProject.minecraft_version}${project.yarn_version}/"
)
// Disable the crazy super-strict doclint tool in Java 8
addStringOption("Xdoclint:none", "-quiet")
}
allprojects.each {
if (it.name == "deprecated") return
source(it.sourceSets.main.allJava)
source(it.sourceSets.client.allJava)
}
classpath = files(sourceSets.main.compileClasspath, sourceSets.client.compileClasspath)
include("**/api/**")
failOnError true
}
task javadocJar(type: Jar) {
dependsOn javadoc
from javadoc.destinationDir
//Set as `fatjavadoc` to prevent an ide form trying to use this javadoc, over using the modules javadoc
archiveClassifier = "fatjavadoc"
}
build.dependsOn javadocJar
loom {
runs {
gametest {
inherit testmodServer
name "Game Test"
// Enable the gametest runner
vmArg "-Dfabric-api.gametest"
vmArg "-Dfabric-api.gametest.report-file=${project.buildDir}/junit.xml"
runDir "build/gametest"
}
autoTestServer {
inherit testmodServer
name "Auto Test Server"
vmArg "-Dfabric.autoTest"
}
autoTestClient {
inherit testmodClient
name "Auto Test Client"
vmArg "-Dfabric.autoTest"
}
// Create duplicate tasks for this, as jacoco slows things down a bit
gametestCoverage {
inherit gametest
name "Game Test Coverage"
ideConfigGenerated = false
}
autoTestClientCoverage {
inherit autoTestClient
name "Auto Test Client Coverage"
ideConfigGenerated = false
}
}
}
test.dependsOn runGametest
def coverageTasks = [runGametestCoverage, runAutoTestClientCoverage]
jacoco {
coverageTasks.forEach {
applyTo it
}
}
task coverage(type: JacocoReport, dependsOn: coverageTasks) {
coverageTasks.forEach {
executionData it
}
// Add all source as input
allprojects { p ->
if (p.path.startsWith(":deprecated")) return
sourceSets p.sourceSets.main, p.sourceSets.client, p.sourceSets.testmod
}
// Exclude mixins
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: '**/mixin/**')
}))
}
}
configurations {
productionRuntime {
extendsFrom configurations.minecraftLibraries
extendsFrom configurations.loaderLibraries
extendsFrom configurations.minecraftRuntimeOnlyLibraries
}
}
dependencies {
productionRuntime "net.fabricmc:fabric-loader:${project.loader_version}"
productionRuntime "net.fabricmc:intermediary:${project.minecraft_version}"
}
import net.fabricmc.loom.util.OperatingSystem
// This is very far beyond loom's API if you copy this, you're on your own.
task runProductionAutoTestClient(type: JavaExec, dependsOn: [remapJar, remapTestmodJar]) {
classpath.from configurations.productionRuntime
mainClass = "net.fabricmc.loader.impl.launch.knot.KnotClient"
workingDir = file("run")
afterEvaluate {
dependsOn downloadAssets
}
doFirst {
classpath.from loom.minecraftProvider.minecraftClientJar
workingDir.mkdirs()
args(
"--assetIndex", loom.minecraftProvider.versionInfo.assetIndex().fabricId(loom.minecraftProvider.minecraftVersion()),
"--assetsDir", new File(loom.files.userCache, "assets").absolutePath,
"--gameDir", workingDir.absolutePath
)
if (OperatingSystem.CURRENT_OS == OperatingSystem.MAC_OS) {
jvmArgs(
"-XstartOnFirstThread"
)
}
jvmArgs(
"-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}",
"-Dfabric.autoTest"
)
}
}
subprojects {
if (it.name == "deprecated") return
dependencies {
testmodImplementation sourceSets.main.output
// Make all modules depend on the gametest api (and thus res loader) to try and promote its usage.
if (project.name != "fabric-gametest-api-v1") {
testmodImplementation project(path: ':fabric-gametest-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-resource-loader-v0', configuration: 'namedElements')
}
// Make all testmods run with registry-sync-v0 as it is required to register new objects.
if (project.name != "fabric-registry-sync-v0") {
testmodRuntimeOnly project(path: ':fabric-registry-sync-v0', configuration: 'namedElements')
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(signingEnabled ? signRemapJar.output : remapJar) {
builtBy(signingEnabled ? signRemapJar : remapJar)
}
artifact(remapSourcesJar) {
builtBy remapSourcesJar
}
}
}
}
// We manually handle the pom generation
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
javadoc.enabled = false
afterEvaluate {
// Disable the gen sources task on sub projects
genClientOnlySourcesWithFernFlower.enabled = false
genClientOnlySourcesWithCfr.enabled = false
genCommonSourcesWithCfr.enabled = false
genCommonSourcesWithFernFlower.enabled = false
unpickClientOnlyJar.enabled = false
unpickCommonJar.enabled = false
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(signingEnabled ? signRemapJar.output : remapJar) {
builtBy(signingEnabled ? signRemapJar : remapJar)
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
artifact javadocJar
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
subprojects.each {
// Dont depend on the deprecated modules in the main artifact.
if (it.path.startsWith(":deprecated")) return
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}
// Required until the deprecation is removed. Fabric API's main jar that is published to maven does not contain sub modules.
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
void setupRepositories(RepositoryHandler repositories) {
//repositories.mavenLocal() // uncomment for testing
def ENV = System.getenv()
if (ENV.MAVEN_URL) {
repositories.maven {
url ENV.MAVEN_URL
if (ENV.MAVEN_USERNAME) {
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
}
subprojects.each {
if (it.name == "deprecated") return
remapJar.dependsOn("${it.path}:remapJar")
}
sourceSets {
testmod
}
// These modules are not included in the fat jar, maven will resolve them via the pom.
def devOnlyModules = [
"fabric-gametest-api-v1",
]
dependencies {
afterEvaluate {
subprojects.each {
if (it.name == "deprecated") return
api project(path: "${it.path}", configuration: "namedElements")
clientImplementation project("${it.path}:").sourceSets.client.output
testmodImplementation project("${it.path}:").sourceSets.testmod.output
}
}
}
remapJar {
afterEvaluate {
subprojects.each {
if (it.name in devOnlyModules || it.name == "deprecated") return
// Include the signed or none signed jar from the sub project.
nestedJars.from project("${it.path}").tasks.getByName(signingEnabled ? "signRemapJar" : "remapJar")
}
}
}
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
}
project {
id = "306612"
changelog = ENV.CHANGELOG ?: "No changelog provided"
releaseType = project.prerelease == "true" ? "beta" : "release"
addGameVersion "1.19.3"
addGameVersion "Fabric"
mainArtifact(signingEnabled ? signRemapJar.output : remapJar) {
displayName = "[$project.minecraft_version] Fabric API $project.version"
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
forgeGradleIntegration = false
}
}
if (signingEnabled) {
project.tasks.curseforge.dependsOn signRemapJar
project.tasks.modrinth.dependsOn signRemapJar
build.dependsOn signRemapJar
}
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: (signingEnabled ? signRemapJar : remapJar)) {
onlyIf {
ENV.GITHUB_TOKEN
}
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("[$project.minecraft_version] Fabric API $project.version")
releaseBuilder.body(ENV.CHANGELOG ?: "No changelog provided")
releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(project.prerelease == "true")
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(signingEnabled ? signRemapJar.output.get().getAsFile() : remapJar.archiveFile.get().getAsFile(), "application/java-archive");
}
}
modrinth {
projectId = "fabric-api"
versionName = "[$project.minecraft_version] Fabric API $project.version"
versionType = project.prerelease == "true" ? "beta" : "release"
changelog = ENV.CHANGELOG ?: "No changelog provided"
uploadFile = signingEnabled ? signRemapJar.output : remapJar
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
if (versions.contains(version)) {
throw new RuntimeException("${version} has already been released!")
}
}
}
github.mustRunAfter checkVersion
project.tasks.modrinth.mustRunAfter checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion