-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.gradle
657 lines (535 loc) · 16.7 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
plugins {
id "java-library"
id "eclipse"
id "idea"
id "maven-publish"
id "fabric-loom" version "1.7.2" apply false
id "legacy-looming" version "1.7.7" apply false
id "com.diffplug.spotless" version "6.20.0"
id "org.ajoberstar.grgit" version "3.1.0"
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
}
def ENV = System.getenv()
setVersion("${project.base_version}")
logger.lifecycle("Building Fabric: " + version)
def supportedVersions = [
"1.12.2",
"1.11.2",
"1.10.2",
"1.9.4",
"1.8.9",
"1.8",
"1.7.10",
"1.6.4"
]
def supportedRanges = [
// ["1.8", "1.8.9", false] // third parameter is whether or not to include snapshots in the range.
]
import groovy.json.JsonSlurper
import net.fabricmc.loom.task.RemapJarTask
import net.legacyfabric.VersionHelper
import org.apache.commons.codec.digest.DigestUtils
static def getMCVersion(Project project) {
def projectFullName = project.name
if (!projectFullName.contains("_")) return "1.8.9"
def mcVersion = projectFullName.split("_")[1]
if (mcVersion == "common") return "1.8.9"
return mcVersion
}
static def getProjectSimpleName(Project project) {
def projectFullName = project.name
if (!projectFullName.contains("_")) return projectFullName
return projectFullName.split("_")[0].trim()
}
def getProjectMavenName(projectLike) {
Project project
if (!(projectLike instanceof Project)) {
if (projectLike instanceof BasePluginExtension) {
project = rootProject.findProject("${projectLike.archivesName.get()}".toString())
} else {
project = rootProject.findProject("$projectLike.name".toString())
}
}
else project = projectLike
def simpleName = getProjectSimpleName(project)
if (project.name.endsWith("_common")) {
if (project.hasProperty("artifactSuffix")) {
simpleName += project["artifactSuffix"]
} else {
simpleName += "-common"
}
}
return simpleName.trim()
}
static def getMCRange(Project project) {
def predicates = []
if (project.hasProperty("minVersionIncluded") && project.hasProperty("maxVersionIncluded")
&& project["minVersionIncluded"] == project["maxVersionIncluded"]
) {
predicates.add(project["maxVersionIncluded"])
} else {
if (project.hasProperty("minVersionIncluded")) {
predicates.add(">=${VersionHelper.parseVersion(project["minVersionIncluded"]).friendlyString}")
}
if (project.hasProperty("minVersionExcluded")) {
predicates.add(">${VersionHelper.parseVersion(project["minVersionExcluded"]).friendlyString}")
}
if (project.hasProperty("maxVersionIncluded")) {
predicates.add("<=${VersionHelper.parseVersion(project["maxVersionIncluded"]).friendlyString}")
}
if (project.hasProperty("maxVersionExcluded")) {
predicates.add("<${VersionHelper.parseVersion(project["maxVersionExcluded"]).friendlyString}")
}
if (predicates.isEmpty()) predicates.add("*")
}
return predicates.join(" ")
}
def getSubprojectVersion(Project project) {
def version
def nameParts = project.name.split("_")
def projectName = nameParts[0]
def mcVersion = nameParts[1]
if (projectName == "legacyfabric-api") version = rootProject.version
else version = rootProject[projectName + ".version"]
if (mcVersion != "common") {
version = version + "+" + mcVersion
}
if (projectName == "legacyfabric-api") return version
if (grgit == null) {
return version + "+nogit"
}
def latestCommits = grgit.log(paths: [rootProject.projectDir.toPath().relativize(project.projectDir.toPath()).toString()], maxCommits: 1)
if (latestCommits.isEmpty()) {
return version + "+uncommited"
} else {
return version + "+" + latestCommits.get(0).id.substring(0, 8) +
DigestUtils.sha256Hex("${project.name}").substring(0, 2) +
DigestUtils.sha256Hex("${mcVersion}").substring(0, 2)
}
}
def getBranch() {
if (ENV.GIT_BRANCH) {
def branch = ENV.GIT_BRANCH
return branch.substring(branch.lastIndexOf("/") + 1)
}
if (grgit == null) {
return "unknown"
}
def branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
def static setupRepositories(RepositoryHandler repositories) {
def ENV = System.getenv()
if (ENV.MAVEN_PUBLISH_CREDENTIALS) {
repositories.maven {
url "https://repo.legacyfabric.net/repository/legacyfabric"
credentials {
username ENV.MAVEN_PUBLISH_CREDENTIALS.split(":")[0]
password ENV.MAVEN_PUBLISH_CREDENTIALS.split(":")[1]
}
authentication {
basic(BasicAuthentication)
}
}
}
}
def moduleDependencies(Project project, List<String> projectNames) {
def depNames = []
def projectMCVersion = VersionHelper.parseVersion(getMCVersion(project))
def isCommon = project.name.endsWith("_common")
rootProject.subprojects {
def subProjectName = getProjectSimpleName(it)
if (projectNames.contains(subProjectName)) {
def predicate = VersionHelper.parsePredicate(getMCRange(it))
if (predicate.test(projectMCVersion)) depNames.add(it.name)
}
}
if (!isCommon) {
def commonProject = findProject(":${getProjectSimpleName(project)}_common")
if (commonProject != null) {
depNames.add(0, commonProject.name)
}
} else {
depNames.removeIf { !it.endsWith("_common")}
}
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: "namedElements") }
def testOutputs = depNames.iterator().collect { findProject(":$it").sourceSets.testmod.output }
project.dependencies {
deps.each {
api it
}
testOutputs.each {
testmodImplementation it
}
}
if (getProjectSimpleName(project) != "legacy-fabric-logger-api-v1") {
deps.add(project.dependencies.project(path: ":legacy-fabric-logger-api-v1_common", configuration: "namedElements"))
}
// 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", getProjectMavenName(it))
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
def exclusionsNode = depNode.appendNode("exclusions")
def exclusionNode = exclusionsNode.appendNode("exclusion")
exclusionNode.appendNode("groupId", "net.legacyfabric.legacy-fabric-api")
exclusionNode.appendNode("artifactId", "*")
}
}
}
}
}
}
allprojects {
group = "net.legacyfabric.legacy-fabric-api"
apply plugin: "java-library"
apply plugin: "checkstyle"
apply plugin: "maven-publish"
apply plugin: "signing"
apply plugin: "fabric-loom"
apply plugin: "legacy-looming"
apply plugin: "com.diffplug.spotless"
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
publishing {
setupRepositories(repositories)
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 8
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
// Must be added before the split source sets are setup.
withSourcesJar()
}
sourceSets {
testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}
System.out.println("Project: $it.name")
if (it != rootProject) {
setVersion(getSubprojectVersion(it))
}
def mcVersion = getMCVersion(it)
String projectName = getProjectSimpleName(it)
def hasTest = it.file("src/testmod").exists()
loom {
mixin {
useLegacyMixinAp = true
}
runs {
"testModClient$mcVersion" {
client()
ideConfigGenerated projectName == "legacyfabric-api"
name = "$mcVersion Testmod Client"
source sourceSets.testmod
if (VersionHelper.needUserProperties(mcVersion)) {
programArgs "--userProperties", "{}"
}
}
"testModServer$mcVersion" {
server()
ideConfigGenerated projectName == "legacyfabric-api"
name = "$mcVersion Testmod Server"
source sourceSets.testmod
}
}
}
allprojects.each { p ->
if (p.file("src/main").exists()) {
loom.mods.register(p.name) {
sourceSet p.sourceSets.main
}
}
if (p.file("src/testmod").exists()) {
loom.mods.register(p.name + "-testmod") {
sourceSet p.sourceSets.testmod
}
}
}
dependencies {
minecraft "com.mojang:minecraft:${mcVersion}"
mappings legacy.yarn(mcVersion, project.yarn_mappings_build)
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
implementation "com.mojang:brigadier:1.0.17"
testmodImplementation sourceSets.main.output
}
tasks.withType(ProcessResources).configureEach {
inputs.property "version", project.version
inputs.property "minecraft_version", getMCRange(project)
filesMatching("fabric.mod.json") {
expand "version": project.version, "minecraft_version": getMCRange(project)
}
}
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER"))
removeUnusedImports()
importOrder("java", "javax", "", "net.minecraft", "net.fabricmc", "net.legacyfabric")
indentWithTabs()
trimTrailingWhitespace()
targetExclude('**/lib/sponge/*.java', '**/lib/sponge/**/*.java')
}
format("sponge", com.diffplug.gradle.spotless.JavaExtension) {
licenseHeaderFile(rootProject.file("SPONGE_HEADER"))
removeUnusedImports()
importOrder("java", "javax", "", "net.minecraft", "net.fabricmc", "net.legacyfabric")
indentWithTabs()
trimTrailingWhitespace()
target('**/lib/sponge/*.java', '**/lib/sponge/**/*.java')
}
}
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "10.11.0"
}
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
if (hasTest) {
task testmodJar(type: Jar) {
from sourceSets.testmod.output
destinationDirectory = project.layout.buildDirectory.dir("devlibs")
archiveClassifier.set("testmod")
}
}
[jar, sourcesJar].each {
it.from(rootProject.file("LICENSE")) {
rename { "${it}-${project.base.archivesName}" }
}
}
if (hasTest) {
task remapTestmodJar(type: RemapJarTask, dependsOn: testmodJar) {
input = testmodJar.archiveFile
archiveClassifier.set("testmod")
addNestedDependencies = false
}
build.dependsOn remapTestmodJar
}
}
remapTestmodJar {
def testModJarTasks = []
subprojects {
if (!it.file("src/testmod").exists()) return
testModJarTasks += it.tasks.remapTestmodJar
}
nestedJars.setFrom(testModJarTasks)
addNestedDependencies = true
}
javadoc {
options {
failOnError = false
source = "8"
encoding = "UTF-8"
charSet = "UTF-8"
memberLevel = JavadocMemberLevel.PACKAGE
links(
"https://guava.dev/releases/21.0/api/docs/",
"https://asm.ow2.io/javadoc/",
"https://docs.oracle.com/javase/8/docs/api/",
"https://jenkins.liteloader.com/job/Mixin/javadoc/",
"https://logging.apache.org/log4j/2.x/log4j-api/apidocs/"
// Need to add minecraft jd publication etc once there is one available
)
// Disable the crazy super-strict doclint tool in Java 8
addStringOption("Xdoclint:none", "-quiet")
}
allprojects.each {
source(it.sourceSets.main.allJava.srcDirs)
}
classpath = sourceSets.main.compileClasspath
include("**/api/**")
failOnError false
}
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.set("fatjavadoc")
}
build.dependsOn javadocJar
def addPomMetadataInformation(Project project, MavenPom pom) {
def modJsonFile = project.file("src/main/resources/fabric.mod.json")
if (!modJsonFile.exists()) {
modJsonFile = project.file("src/client/resources/fabric.mod.json")
}
def modJson = new JsonSlurper().parse(modJsonFile)
pom.name = modJson.name
pom.url = "https://github.com/Legacy-Fabric/fabric/tree/HEAD/${project.rootDir.relativePath(project.projectDir)}"
pom.description = modJson.description
pom.licenses {
license {
name = "Apache-2.0"
url = "https://github.com/Legacy-Fabric/fabric/blob/HEAD/LICENSE"
}
}
pom.developers {
developer {
name = "Legacy Fabric"
url = "https://legacyfabric.net/"
}
}
pom.scm {
connection = "scm:git:https://github.com/Legacy-Fabric/fabric.git"
url = "https://github.com/Legacy-Fabric/fabric"
developerConnection = "scm:git:git@github.com:Legacy-Fabric/fabric.git"
}
pom.issueManagement {
system = "GitHub"
url = "https://github.com/Legacy-Fabric/fabric/issues"
}
}
subprojects {
base {
archivesName = getProjectMavenName(it)
}
dependencies {
testmodImplementation sourceSets.main.output
if (getProjectSimpleName(project) != "legacy-fabric-logger-api-v1") {
api project(path: ":legacy-fabric-logger-api-v1_common", configuration: "namedElements")
}
}
publishing {
publications {
mavenJava(MavenPublication) {
if (getProjectSimpleName(project) == "legacyfabric-api") {
artifactId = "legacy-fabric-api"
} else {
artifactId = getProjectMavenName(project)
}
pom {
addPomMetadataInformation(project, pom)
}
artifact(remapJar) {
builtBy remapJar
}
artifact(remapSourcesJar) {
builtBy remapSourcesJar
}
}
}
}
// We manually handle the pom generation
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
javadoc.enabled = false
def scriptPath = rootProject.file("${getProjectSimpleName(project)}/common.gradle")
if (scriptPath.exists()) {
apply from: rootProject.file("${getProjectSimpleName(project)}/common.gradle")
}
afterEvaluate {
// Disable the gen sources task on sub projects
genSourcesWithFernFlower.enabled = false
genSourcesWithCfr.enabled = false
// genClientOnlySourcesWithFernFlower.enabled = false
// genClientOnlySourcesWithCfr.enabled = false
// genCommonSourcesWithCfr.enabled = false
// genCommonSourcesWithFernFlower.enabled = false
}
}
publishing {
publications {}
}
subprojects {
project.tasks.withType(PublishToMavenLocal).each {
it.outputs.file("$rootProject.projectDir/temp")
}
project.tasks.withType(PublishToMavenRepository).each {
it.outputs.file("$rootProject.projectDir/temp")
}
}
subprojects.each { if (it.file("src/main").exists()) remapJar.dependsOn("${it.path}:remapJar") }
sourceSets {
testmod
}
dependencies {
afterEvaluate {
subprojects.each {
if (getProjectSimpleName(it) == "legacyfabric-api") return
if (it.file("src/main").exists()) api project(path: "${it.path}", configuration: "namedElements")
if (it.file("src/testmod").exists()) testmodImplementation project("${it.path}").sourceSets.testmod.output
}
}
}
remapJar {
afterEvaluate {
subprojects.each {
if (getProjectSimpleName(it) == "legacyfabric-api") return
// Include the signed or none signed jar from the sub project.
if (it.file("src/main").exists()) nestedJars.from project("${it.path}:").tasks.getByName("remapJar")
}
}
}
publishMods {
file = remapJar.archiveFile
changelog = providers.environmentVariable("CHANGELOG").getOrElse("A changelog can be found at https://github.com/Legacy-Fabric/fabric/commits")
type = STABLE
displayName = "Legacy Fabric API $project.version"
modLoaders.add("fabric")
dryRun = providers.environmentVariable("CURSE_API_KEY").getOrNull() == null
curseforge {
accessToken = providers.environmentVariable("CURSE_API_KEY")
projectId = "400281"
projectSlug = "legacy-fabric-api"
minecraftVersions.addAll(supportedVersions)
if (!supportedRanges.isEmpty()) {
supportedRanges.each { range ->
minecraftVersionRange {
start = range[0]
end = range[1]
}
}
}
}
modrinth {
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
projectId = "9CJED7xi"
minecraftVersions.addAll(supportedVersions)
if (!supportedRanges.isEmpty()) {
supportedRanges.each { range ->
minecraftVersionRange {
start = range[0]
end = range[1]
includeSnapshots = range[2]
}
}
}
}
github {
accessToken = providers.environmentVariable("GITHUB_TOKEN")
repository = providers.environmentVariable("GITHUB_REPOSITORY").getOrElse("LegacyFabric/dryrun")
commitish = providers.environmentVariable("GITHUB_REF_NAME").getOrElse("dryrun")
}
discord {
webhookUrl = providers.environmentVariable("DISCORD_WEBHOOK")
dryRunWebhookUrl = ""
username = "Legacy Fabric Bot"
content = changelog.map { "# Legacy Fabric API $project.version has been released! \n" + it}
}
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.legacyfabric.net/net/legacyfabric/legacy-fabric-api/legacy-fabric-api/maven-metadata.xml").text
def metadata = new groovy.xml.XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text()
versions.each {
if (it.startsWith(project.version + "+1.8.9")) {
throw new RuntimeException("${project.version} has already been released!")
}
}
}
}
tasks.publishMods.dependsOn checkVersion
publish.mustRunAfter checkVersion