-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
527 lines (461 loc) · 19.2 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
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
import com.diffplug.gradle.spotless.SpotlessExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.hypherionmc.modpublisher.plugin.ModPublisherGradleExtension
import xyz.wagyourtail.jvmdg.gradle.task.files.DowngradeFiles
import xyz.wagyourtail.replace_str.ProcessClasses
import xyz.wagyourtail.unimined.api.UniminedExtension
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import java.util.*
plugins {
java
id("xyz.wagyourtail.unimined") version "1.3.12" apply false
id("xyz.wagyourtail.jvmdowngrader") version "1.2.1"
id("com.diffplug.gradle.spotless") version "6.25.0" apply false
id("com.gradleup.shadow") version "8.3.5" apply false
id("com.hypherionmc.modutils.modpublisher") version "2.1.6" apply false
}
/**
* Retrieve a Project Property
*/
operator fun String.invoke(): String? {
return project.properties[this] as String?
}
val extMcVersion = if ("display_version"()!!.isNotEmpty()) "display_version"() else "mc_version"()
val extVersionLabel = "${if ("versionLabel"().equals("release", ignoreCase = true)) "" else "versionLabel"()}"
val extModName = "mod_name"()!!
val extModId = "mod_id"()!!
val extVersionInfoLabel = if (extVersionLabel.isEmpty()) "" else "-$extVersionLabel"
val extBaseVersionLabel = ("versionId"() + extVersionInfoLabel.replace(Regex("\\s"), ".")).lowercase()
val extClassPath = "${rootProject.group}".replace(".", "/") + "/$extModId"
val extVersionFormat = "$extBaseVersionLabel+$extMcVersion"
val extFileFormat = "$extModName-$extVersionFormat"
val extDisplayFormat = extVersionFormat.replace(Regex("\\s"), "").lowercase()
val extProtocol = "mc_protocol"()!!.toInt()
val extIsLegacy = "isLegacy"()!!.toBoolean()
val extIsJarMod = "isJarMod"()!!.toBoolean()
val extIsModern = !extIsLegacy && extProtocol >= 498
val extIsMCPJar = extIsJarMod && "mc_mappings_type"() == "mcp"
// Only apply ATs to forge on non-legacy builds, or on Legacy Protocols above 1.5
// due to the way Forge requires core-mods for lower version usage
val extAWFile = file("$rootDir/fabric/src/main/resources/$extModId.accesswidener")
val extCanUseATs = extAWFile.exists() && (!extIsLegacy || extProtocol > 60)
// Setup Game Versions to upload for
val uploadVersions = mutableListOf("mc_version"()!!)
for (v in "additional_mc_versions"()!!.split(",")) {
if (v.isNotEmpty()) {
uploadVersions.add(v)
}
}
subprojects {
val isLoaderSource = path != ":common"
apply(plugin = "java")
apply(plugin = "xyz.wagyourtail.unimined")
apply(plugin = "xyz.wagyourtail.jvmdowngrader")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "com.gradleup.shadow")
if (isLoaderSource) {
apply(plugin = "com.hypherionmc.modutils.modpublisher")
}
val modName by extra(extModName)
val modId by extra(extModId)
val versionInfoLabel by extra(extVersionInfoLabel)
val baseVersionLabel by extra(extBaseVersionLabel)
val classPath by extra(extClassPath)
val versionFormat by extra(extVersionFormat)
val fileFormat by extra(extFileFormat)
val displayFormat by extra(extDisplayFormat)
val protocol by extra(extProtocol)
val isLegacy by extra(extIsLegacy)
val isJarMod by extra(extIsJarMod)
val isModern by extra(extIsModern)
val isMCPJar by extra(extIsMCPJar)
val accessWidenerFile by extra(extAWFile)
val canUseATs by extra(extCanUseATs)
val mcVersionLabel by extra(extMcVersion)
val versionLabel by extra(extVersionLabel)
val mcVersion by extra("mc_version"()!!)
val mcMappingsType by extra("mc_mappings_type"())
val uniLibMinVersion by extra("unilib_minimum_version"()!!)
val displayLoaderName =
name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
extensions.getByType<SpotlessExtension>().apply {
java {
licenseHeaderFile(rootProject.file("HEADER"))
}
}
version = versionFormat
group = rootProject.group
extensions.getByType<BasePluginExtension>().apply {
archivesName = modName
}
val sourceVersion = "source_java_version"()?.let { JavaVersion.toVersion(it) }!!
val sourceVersionInt = Integer.parseInt(sourceVersion.majorVersion)
val buildVersion = "build_java_version"()?.let { JavaVersion.toVersion(it) }!!
val buildVersionInt = Integer.parseInt(buildVersion.majorVersion)
val canDowngrade = sourceVersionInt > buildVersionInt
val shouldDowngrade = canDowngrade && isLoaderSource
val sourceSets = extensions.getByType<SourceSetContainer>()
extensions.getByType<JavaPluginExtension>().apply {
toolchain {
languageVersion.set(JavaLanguageVersion.of(sourceVersionInt))
}
withSourcesJar()
}
repositories {
mavenLocal()
mavenCentral()
// ModLoader Mavens
maven("https://maven.minecraftforge.net/") {
name = "Forge"
metadataSources {
mavenPom()
artifact()
}
}
maven("https://maven.neoforged.net/releases") {
name = "NeoForged"
}
maven("https://maven.fabricmc.net/") {
name = "Fabric"
}
maven("https://maven.legacyfabric.net/") {
name = "Legacy Fabric"
}
// WagYourTail Mavens
maven("https://maven.wagyourtail.xyz/releases")
maven("https://maven.wagyourtail.xyz/snapshots")
// LenniReflect Mavens
maven("https://maven.lenni0451.net/releases/")
maven("https://maven.lenni0451.net/snapshots/")
// OSS Mavens
maven("https://s01.oss.sonatype.org/content/repositories/releases")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
// HypherionMC Mavens
maven("https://maven.firstdark.dev/releases")
maven("https://maven.firstdark.dev/snapshots")
// Mod Integration Mavens
if (isModern) {
maven("https://maven.terraformersmc.com/releases/") {
name = "TerraformersMC"
}
}
}
// debug, puts some things in build/unimined instead of ~/.gradle/caches/unimined
extensions.getByType<UniminedExtension>().useGlobalCache = true
extensions.getByType<UniminedExtension>().minecraft(sourceSets.getByName("main"), true) {
side(if (isJarMod) "client" else "combined")
version(mcVersion)
mappings {
val mcMappings = "mc_mappings"()!!
when (mcMappingsType) {
"mcp" -> {
if (!isJarMod) {
searge()
}
mcp(if (isJarMod) "legacy" else "stable", mcMappings) {
if (!isJarMod) {
clearOutputs()
outputs("mcp", true) { listOf("intermediary") }
}
}
}
"forgeMCP" -> {
forgeBuiltinMCP("forge_version"()!!) {
clearContains()
clearOutputs()
contains({ _, t ->
!t.contains("MCP")
}) {
onlyExistingSrc()
outputs("searge", false) { listOf("official") }
}
contains({ _, t ->
t.contains("MCP")
}) {
outputs("mcp", true) { listOf("intermediary") }
sourceNamespace("searge")
}
}
officialMappingsFromJar {
clearContains()
clearOutputs()
outputs("official", false) { listOf() }
}
}
"retroMCP" -> {
retroMCP(mcMappings)
}
"yarn" -> {
yarn(mcMappings)
}
"mojmap" -> {
mojmap {
skipIfNotIn("intermediary")
}
}
"parchment" -> {
mojmap {
skipIfNotIn("intermediary")
}
parchment(mcVersion, mcMappings)
}
else -> throw GradleException("Unknown or Unsupported Mappings version")
}
// Only use Intermediaries on Versions that support it
val usingIntermediary = (isLegacy && protocol >= 39) || !isLegacy
if (usingIntermediary) {
if (isModern) {
intermediary()
} else {
legacyIntermediary()
}
}
// ability to add custom mappings
val target = if (!isModern) "mcp" else "mojmap"
stub.withMappings("searge", target) {
c("ModLoader", "net/minecraft/src/ModLoader", "net/minecraft/src/ModLoader")
c("BaseMod", "net/minecraft/src/BaseMod", "net/minecraft/src/BaseMod")
// Fix: Fixed an inconsistent mapping in 1.16 and 1.16.1 between MCP and Mojmap
if (!isLegacy && (protocol == 735 || protocol == 736)) {
c(
"dng",
listOf(
"net/minecraft/client/gui/widget/Widget",
"net/minecraft/client/gui/components/AbstractWidget"
)
) {
m("e", "()I", "func_238483_d_", "getHeightRealms")
}
}
}
if (isMCPJar) {
if (protocol <= 2) { // MC a1.1.2_01 and below
devNamespace("searge")
} else {
devFallbackNamespace("searge")
}
} else if (usingIntermediary) {
devFallbackNamespace("intermediary")
}
if (shouldDowngrade) {
val apiVersion = if (buildVersion.isJava7) JavaVersion.VERSION_1_8 else buildVersion
val downgradeClient = tasks.register("downgradeClient", DowngradeFiles::class.java) {
inputCollection = sourceSet.output.classesDirs + sourceSet.runtimeClasspath
classpath = project.files()
outputCollection.files
}
runs.config("client") {
classpath = downgradeClient.get().outputCollection + files(jvmdg.getDowngradedApi(apiVersion))
}
}
}
minecraftRemapper.config {
// most mcp mappings (except older format) dont include field desc
ignoreFieldDesc(true)
// this also fixes some issues with them, as it tells tiny remapper to try harder to resolve conflicts
ignoreConflicts(true)
}
}
// Setup UniLib attachment data
val libPrefix = "unilib_name"()!!
val libName = if (!isLoaderSource) "fabric" else name
val libVersion = "unilib_build_version"()!!
val libFile = "$libName${if (canDowngrade) "-native" else ""}"
dependencies {
// Annotations
"compileOnly"("com.google.code.findbugs:jsr305:3.0.2")
"compileOnly"("com.github.spotbugs:spotbugs-annotations:4.8.6")
// Attach UniLib dependency
"modImplementation"(
"com.gitlab.cdagaming.unilib:$libPrefix-${
libName.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}:$libVersion+$mcVersionLabel:$libFile"
)
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We"ll use that if it"s available, but otherwise we"ll use the older option.
if (sourceVersion.isJava9Compatible) {
options.release.set(sourceVersionInt)
}
}
tasks.named<Jar>("jar").configure {
manifest {
attributes(
mapOf(
"Specification-Title" to modName,
"Specification-Vendor" to "CDAGaming",
"Specification-Version" to "1", // We are version 1 of ourselves
"Implementation-Title" to modName,
"Implementation-Version" to archiveVersion.get(),
"Implementation-Vendor" to "CDAGaming"
)
)
}
}
val relocatePath = "$modId.external"
tasks.named<ShadowJar>("shadowJar").configure {
// Meta Exclusions
exclude("**/DEPENDENCIES*")
exclude("**/LICENSE*")
exclude("**/Log4J*")
exclude("META-INF/NOTICE*")
exclude("META-INF/versions/**")
// JUnixSocket exclusions:
// libs
// discord doesn't support bsd or sun
exclude("lib/*BSD*/**")
exclude("lib/*Sun*/**")
// we don't use junixsocket on windows
exclude("lib/*Window*/**")
// include only arm on mac
exclude("lib/aarch64-Linux*/**")
// doesn't support these architectures
exclude("lib/ppc*/**")
exclude("lib/risc*/**")
exclude("lib/s390x*/**")
exclude("lib/arm*/**")
// metadata
// discord doesn't support bsd or sun
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-*BSD*/**")
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-*Sun*/**")
// we don't use junixsocket on windows
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-*Window*/**")
// include only arm on mac
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-aarch64-Linux*/**")
// doesn't support these architectures
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-ppc*/**")
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-risc*/**")
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-s390x*/**")
exclude("META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-arm*/**")
// Package Relocations
relocate("net.lenni0451", "$relocatePath.net.lenni0451")
relocate("com.jagrosh", "$relocatePath.com.jagrosh")
relocate("org.meteordev", "$relocatePath.org.meteordev")
relocate("io.github.classgraph", "$relocatePath.io.github.classgraph")
relocate("nonapi.io.github.classgraph", "$relocatePath.nonapi.io.github.classgraph")
if (protocol < 755) {
relocate("org.slf4j", "$relocatePath.org.slf4j")
relocate("org.apache.logging.slf4j", "$relocatePath.org.apache.logging.slf4j")
}
// Integration Relocations
if (!isLegacy) {
relocate("me.hypherionmc", "$relocatePath.me.hypherionmc")
}
}
gradle.projectsEvaluated {
tasks.withType<Javadoc>().configureEach {
options.encoding = "UTF-8"
exclude("**/*Gui.java")
exclude("$classPath/**/config/**")
exclude("$classPath/**/integrations/**")
}
}
tasks.getByName<JavaCompile>("compileJava").apply {
doLast {
ProcessClasses.process(
destinationDirectory.asFile.getOrNull()!!.toPath(), mapOf(
"MOD_ID" to modId,
"MOD_NAME" to modName,
"VERSION_ID" to baseVersionLabel,
"VERSION_TYPE" to "deploymentType"()!!,
"MC_VERSION" to mcVersionLabel,
"MC_PROTOCOL" to protocol.toString(),
"IS_LEGACY" to isLegacy.toString(),
"UNILIB_NAME" to libPrefix,
"UNILIB_MIN_VERSION" to uniLibMinVersion,
"UNILIB_LEGACY_RANGE" to "required-after:unilib@[$uniLibMinVersion,]"
)
)
}
}
afterEvaluate {
if (shouldDowngrade) {
// Setup JVMDG Globals
jvmdg.downgradeTo = buildVersion
jvmdg.shadePath = {
"$modId/jvmdg/api"
}
if (buildVersion.isJava7) {
jvmdg.debugSkipStubs.add(JavaVersion.VERSION_1_8)
}
val resultJar = tasks.getByName<RemapJarTask>("remapJar").asJar
val resultClassifier = resultJar.archiveClassifier.get()
resultJar.archiveClassifier.set("$resultClassifier-native")
tasks.getByName("assemble").dependsOn("shadeDowngradedApi")
tasks.downgradeJar {
dependsOn(resultJar)
inputFile = resultJar.archiveFile.get().asFile
destinationDirectory = temporaryDir
}
tasks.shadeDowngradedApi {
archiveClassifier = resultClassifier
}
tasks.named("preRunClient") {
dependsOn("downgradeClient")
}
}
}
if (isLoaderSource) {
val targetFile = "build/libs/$fileFormat-$name.jar"
val uploadLoaders = mutableListOf(name)
val additionalLoaders = "additional_${name}_loaders"()
if (!additionalLoaders.isNullOrEmpty()) {
for (v in additionalLoaders.split(",")) {
if (v.isNotEmpty()) {
uploadLoaders.add(v)
}
}
}
extensions.getByName<ModPublisherGradleExtension>("publisher").apply {
apiKeys {
curseforge(System.getenv("CF_APIKEY"))
modrinth(System.getenv("MODRINTH_TOKEN"))
nightbloom(System.getenv("NIGHTBLOOM_TOKEN"))
}
debug = false
curseID = "297038"
modrinthID = "DFqQfIBR"
nightbloomID = modId
versionType = "deploymentType"()!!.lowercase()
changelog = file("$rootDir/Changes.md").readText()
projectVersion = "$displayFormat-$name" // Modrinth Only
displayName =
"[$displayLoaderName $mcVersionLabel] $modName v${"versionId"()}${if (versionLabel.isEmpty()) "" else " $versionLabel"}"
gameVersions = uploadVersions
loaders = uploadLoaders
curseEnvironment = "client"
artifact = targetFile
curseDepends {
required("unilib")
}
modrinthDepends {
required("unilib")
}
nightbloomDepends {
required("unilib")
}
}
}
}
tasks.register<Delete>("cleanUniminedCache") {
val uniminedPath = ".gradle/unimined"
// Delete the .gradle/unimined directory in the root project if it exists
delete(rootProject.projectDir.resolve(uniminedPath))
// Delete the .gradle/unimined directory in each subproject if it exists
delete(subprojects.map { it.projectDir.resolve(uniminedPath) })
}
// Ensure the clean task depends on cleanUniminedCache
tasks.named("clean") {
dependsOn("cleanUniminedCache")
}
tasks {
jar {
enabled = false
}
}