-
Notifications
You must be signed in to change notification settings - Fork 45
/
build.gradle
537 lines (451 loc) · 15 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
buildscript {
repositories {
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
mavenCentral()
mavenLocal()
}
dependencies {
classpath "cuchaz:enigma-cli:${project.enigma_version}"
classpath "net.fabricmc:name-proposal:${project.name_proposal_version}"
}
}
plugins {
id 'java' // for constants, packages, javadoc
id 'maven-publish'
id "com.diffplug.spotless" version "6.21.0"
id 'net.fabricmc.filament' version "0.7.1"
id 'net.legacyfabric.multifilament' version "0.4.1" apply false
}
def taskName = project.gradle.startParameter.taskNames[0]
def ENV = System.getenv()
def minecraft_version = "1.8.9"
if (!ENV.MC_VERSION) {
System.err.println("No Minecraft version selected! Please use yarn.py to start gradle.")
System.err.println("Defaulting Minecraft version to ${minecraft_version}")
} else {
minecraft_version = ENV.MC_VERSION
}
filament {
minecraftVersion = minecraft_version
}
apply plugin:"net.legacyfabric.multifilament"
def mapJarGroup = "jar mapping"
// Fetch build number from Github Actions
def build_number = ENV.GITHUB_RUN_NUMBER && taskName != "publishToMavenLocal" ? ENV.GITHUB_RUN_NUMBER : "local"
if (build_number != "local") {
def build_num = Integer.valueOf(build_number);
def latest_num = getLastBuildNumber();
if (latest_num > build_num) {
build_number = String.valueOf(latest_num);
}
}
def yarnVersion = "${minecraft_version}+build.$build_number"
version = yarnVersion
multiFilament {
intermediaryRevision = intermediary_version.toInteger()
activeMappingsDir = file("mappings-active")
multiMappingsDir = file("mappings")
tempMappingsDir = file("mappings-temp")
it.yarnGroup = "yarn"
it.buildMappingGroup = "mapping build"
it.mapJarGroupGroup = mapJarGroup
it.version = yarnVersion
it.unpickDefinitionsDir = file("unpick-definitions")
it.unpickMetaFile = file("unpick-definitions/unpick.json")
it.unpickVersion = project.unpick_version
}
System.out.println("Preparing yarn ${yarnVersion}")
repositories {
mavenCentral()
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
maven {
name "Mojang"
url 'https://libraries.minecraft.net/'
metadataSources {
artifact()
ignoreGradleMetadataRedirection()
}
}
}
dependencies {
enigmaRuntime "cuchaz:enigma-swing:${project.enigma_version}"
enigmaRuntime "net.fabricmc:name-proposal:${project.name_proposal_version}"
enigmaRuntime "net.fabricmc:cfr:${project.cfr_version}"
javadocClasspath "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
javadocClasspath "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
javadocClasspath "com.google.code.findbugs:jsr305:3.0.2" // for some other jsr annotations
decompileClasspath "net.fabricmc:cfr:${project.cfr_version}"
mappingPoetJar "net.fabricmc:mappingpoet:${project.mappingpoet_version}"
asm "org.ow2.asm:asm:${project.asm_version}"
asm "org.ow2.asm:asm-tree:${project.asm_version}"
asm "org.ow2.asm:asm-commons:${project.asm_version}"
asm "org.ow2.asm:asm-util:${project.asm_version}"
}
def minecraftLibraries = configurations.minecraftLibraries
import com.diffplug.spotless.LineEnding
import cuchaz.enigma.command.CheckMappingsCommand
import net.fabricmc.filament.task.MapJarTask
import net.fabricmc.filament.task.UnpickJarTask
import net.fabricmc.filament.task.mappingio.MergeMappingsTask
import net.fabricmc.mappingio.format.MappingFormat
import net.fabricmc.nameproposal.MappingNameCompleter
import org.gradle.work.DisableCachingByDefault
import net.legacyfabric.multifilament.task.FileInputOutput
def getIntermediaryGroup() {
switch(multiFilament.intermediaryRevision.get()) {
case "2":
return ".v2"
default:
return ""
}
}
tasks.register('yarn', EnigmaTask) {
dependsOn mapIntermediaryJar, versionifyMappingsExclude
group = multiFilament.yarnGroup.get()
jar = mapIntermediaryJar.output
mappings = multiFilament.activeMappingsDir.asFile
}
tasks.register('yarnCommon', EnigmaTask) {
dependsOn versionifyMappingsExclude
group = multiFilament.yarnGroup.get()
jar = mapServerIntermediaryJar.output
mappings = multiFilament.activeMappingsDir.asFile
}
tasks.register('checkMappings') {
dependsOn versionifyMappingsExclude
group = multiFilament.buildMappingGroup.get()
inputs.dir multiFilament.activeMappingsDir.asFile
inputs.file mapIntermediaryJar.output
def intermediaryJarPath = mapIntermediaryJar.outputFile.absolutePath
def activeMappingsDir = multiFilament.activeMappingsDir.asFile.get().getAbsolutePath()
doLast {
String[] args = [
intermediaryJarPath,
activeMappingsDir
]
try {
new CheckMappingsCommand().run(args)
} catch (IllegalStateException ignored) {
// just print, don't fail the task
}
}
}
// Disable the default jar task
jar {
enabled = false
}
clean.doFirst {
delete multiFilament.tempDirectory, multiFilament.minecraftCacheDirectory
}
sourceSets {
constants
packageDocs // package info files
}
tasks.register('constantsJar', Jar) {
from sourceSets.constants.output
archiveClassifier = "constants"
}
tasks.build.dependsOn "compressTiny","tinyJar","v2UnmergedYarnJar", "v2MergedYarnJar", "javadocJar"
// Setup the build for the unpicked constants
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 17
}
tasks.withType(AbstractArchiveTask).configureEach {
it.preserveFileTimestamps = false
it.reproducibleFileOrder = true
}
spotless {
lineEndings = LineEnding.UNIX
java {
licenseHeaderFile(rootProject.file("HEADER"))
}
}
tasks.register('sourcesJar', Jar) {
dependsOn classes
archiveClassifier = "sources"
from sourceSets.constants.allSource
}
// Only build jars for package infos if we need to actually expose stuff like annotation in the future.
build.dependsOn constantsJar
tasks.register('insertAutoGeneratedEnumMappings', FileInputOutput) {
dependsOn mapIntermediaryJar, downloadIntermediary
group = multiFilament.buildMappingGroup.get()
input = completeMappings.output
output = multiFilament.tempDirectory.file("unmerged-named-v2-with-enum.tiny")
inputs.file mapIntermediaryJar.output
inputs.file downloadIntermediary.output
def intermediaryJarPath = mapIntermediaryJar.outputPath
def intermediaryMappingsPath = downloadIntermediary.outputPath
doLast {
MappingNameCompleter.completeNames(
intermediaryJarPath,
inputPath,
intermediaryMappingsPath,
outputPath
)
}
}
fixedRemapUnpickDefinitionsIntermediary {
group = 'unpick'
output = multiFilament.tempDirectory.file('intermediary-definitions.unpick')
mappings = insertAutoGeneratedEnumMappings.output
}
tasks.register('unpickIntermediaryJar', UnpickJarTask) {
group = 'unpick'
input = mapIntermediaryJar.output
output = multiFilament.getCacheFile("${minecraft_version}-intermediary-unpicked.jar")
unpickDefinition = fixedRemapUnpickDefinitionsIntermediary.output
constantsJarFile = constantsJar.archiveFile
classpath.from minecraftLibraries
}
tasks.register('yarnUnpicked', EnigmaTask) {
dependsOn "unpickIntermediaryJar", versionifyMappingsExclude
group = multiFilament.yarnGroup.get()
jar = unpickIntermediaryJar.output
mappings = multiFilament.activeMappingsDir.asFile
}
tasks.register('mergeV2', MergeMappingsTask) {
group = multiFilament.buildMappingGroup.get()
output = multiFilament.tempDirectory.file("merged-v2.tiny")
mappingInputs.from downloadIntermediary.output
mappingInputs.from insertAutoGeneratedEnumMappings.output
outputFormat = MappingFormat.TINY_2_FILE
}
tasks.register('mapNamedJar', MapJarTask) {
dependsOn mergeV2, unpickIntermediaryJar
group = mapJarGroup
output = multiFilament.getCacheFile("${minecraft_version}-named.jar")
input = unpickIntermediaryJar.output
mappings = mergeV2.output
classpath.from minecraftLibraries
from = 'intermediary'
to = 'named'
classMappings = [
"javax/annotation/Nullable" : "org/jetbrains/annotations/Nullable",
"javax/annotation/Nonnull" : "org/jetbrains/annotations/NotNull",
"javax/annotation/concurrent/Immutable": "org/jetbrains/annotations/Unmodifiable"
]
}
def mcLibsDir = file('build/tmp/mclibs')
// Task to copy all the mc libs into a single directory.
tasks.register('syncDependencies', Sync) {
from minecraftLibraries
into mcLibsDir
}
def fakeSourceDir = file(".gradle/temp/fakeSource")
tasks.register('genFakeSource', JavaExec) {
dependsOn mergeV2, mapNamedJar, syncDependencies
group = "javadoc generation"
inputs.file mergeV2.output
inputs.file mapNamedJar.output
inputs.dir mcLibsDir
outputs.dir fakeSourceDir
mainClass = "net.fabricmc.mappingpoet.Main"
classpath configurations.mappingPoet
// use merged v2 so we have all namespaces in jd
args mergeV2.outputFile.getAbsolutePath(), mapNamedJar.outputFile.getAbsolutePath(), fakeSourceDir.getAbsolutePath(), mcLibsDir.getAbsolutePath()
}
tasks.register('decompileCFR', JavaExec) {
def outputDir = multiFilament.getIntermediaryRevisionDirectory().get().dir("namedSrc").getAsFile()
dependsOn mapNamedJar
mainClass = "org.benf.cfr.reader.Main"
classpath.from configurations.decompileClasspath
classpath.from minecraftLibraries
args mapNamedJar.outputFile.getAbsolutePath(), "--outputdir", outputDir.absolutePath
doFirst {
outputDir.deleteDir()
}
}
javadoc {
dependsOn genFakeSource
group = "javadoc generation"
def mappingPoetJar = project.provider { zipTree configurations.mappingPoetJar.singleFile }
failOnError = false
maxMemory = '2G'
// verbose = true // enable to debug
options {
// verbose() // enable to debug
source = "17"
encoding = 'UTF-8'
charSet = 'UTF-8'
memberLevel = JavadocMemberLevel.PRIVATE
splitIndex true
tags(
'apiNote:a:API Note:',
'implSpec:a:Implementation Requirements:',
'implNote:a:Implementation Note:'
)
taglets "net.fabricmc.mappingpoet.jd.MappingTaglet"
// taglet path, header, extra stylesheet settings deferred
it.use()
addBooleanOption "-allow-script-in-comments", true
addBooleanOption "-ignore-source-errors", true
links(
'https://guava.dev/releases/31.1-jre/api/docs/',
'https://www.javadoc.io/doc/com.google.code.gson/gson/2.10/',
'https://logging.apache.org/log4j/2.x/log4j-api/apidocs/',
'https://www.slf4j.org/apidocs/',
"https://javadoc.io/doc/org.jetbrains/annotations/${project.jetbrains_annotations_version}/",
'https://javadoc.lwjgl.org/',
'https://fastutil.di.unimi.it/docs/',
'https://javadoc.scijava.org/JOML/',
'https://netty.io/4.1/api/',
'https://www.oshi.ooo/oshi-core-java11/apidocs/',
'https://java-native-access.github.io/jna/5.12.1/javadoc/',
'https://unicode-org.github.io/icu-docs/apidoc/released/icu4j/',
'https://jopt-simple.github.io/jopt-simple/apidocs/',
'https://solutions.weblite.ca/java-objective-c-bridge/docs/',
'https://commons.apache.org/proper/commons-logging/apidocs/',
'https://commons.apache.org/proper/commons-lang/javadocs/api-release/',
'https://commons.apache.org/proper/commons-io/apidocs/',
'https://commons.apache.org/proper/commons-codec/archives/1.15/apidocs/',
'https://commons.apache.org/proper/commons-compress/apidocs/',
'https://hc.apache.org/httpcomponents-client-4.5.x/current/httpclient/apidocs/',
"https://maven.fabricmc.net/docs/fabric-loader-${project.fabric_loader_version}/",
"https://docs.oracle.com/en/java/javase/17/docs/api/"
)
// https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet
addBooleanOption 'Xdoclint:html', true
addBooleanOption 'Xdoclint:syntax', true
addBooleanOption 'Xdoclint:reference', true
addBooleanOption 'Xdoclint:accessibility', true
}
source fileTree(fakeSourceDir) + sourceSets.constants.allJava + sourceSets.packageDocs.allJava
classpath = configurations.javadocClasspath.plus minecraftLibraries
def fs = project.services.get(FileSystemOperations.class)
def outputDir = javadoc.destinationDir
doLast {
fs.copy {
from mappingPoetJar
include "copy_on_click.js"
into outputDir
}
}
def tagletClasspath = configurations.mappingPoet.files.toList()
doFirst {
// lazy setting
options {
tagletPath tagletClasspath
header mappingPoetJar.get().filter { it.name == 'javadoc_header.txt' }.singleFile.text.trim() // cannot include line breaks
addFileOption "-add-stylesheet", mappingPoetJar.get().filter { it.name == 'forms.css' }.singleFile
}
}
}
tasks.register('javadocJar', Jar) {
dependsOn javadoc
group = "javadoc generation"
from javadoc.destinationDir
archiveVersion.set yarnVersion
archiveClassifier = 'javadoc'
}
generatePackageInfoMappings {
dependsOn versionifyMappingsExclude
inputJar = mapIntermediaryJar.output
packageName = "net/minecraft/unused/packageinfo/"
outputDir = multiFilament.activeMappingsDir.dir("net/minecraft/unused/packageinfo")
}
javadocLint {
dependsOn versionifyMappingsExclude
group = "javadoc generation"
mappingDirectory = multiFilament.activeMappingsDir
}
check.dependsOn javadocLint
afterEvaluate {
publishing {
publications {
register("maven", MavenPublication) {
groupId "net.legacyfabric" + getIntermediaryGroup()
artifactId "yarn"
version yarnVersion
artifact(compressTiny.output) {
classifier "tiny"
builtBy compressTiny
}
artifact(tinyJar)
artifact(v2UnmergedYarnJar) {
classifier "v2"
}
artifact(v2MergedYarnJar) {
classifier "mergedv2"
}
artifact(constantsJar) {
classifier "constants"
}
artifact sourcesJar
artifact javadocJar
}
}
repositories {
if (ENV.MAVEN_PUBLISH_CREDENTIALS) {
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)
}
}
}
}
}
}
// A task to ensure that the version being released has not already been released.
tasks.register('checkVersion') {
doFirst {
def xml = new URL("https://maven.legacyfabric.net/net/legacyfabric${getIntermediaryMaven()}/yarn/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!")
}
}
}
publish.mustRunAfter checkVersion
import groovy.json.JsonSlurper;
int getLastBuildNumber() {
def xml = new URL("https://meta.legacyfabric.net/v2/versions/yarn/1.8.9").text
def metadata = new JsonSlurper().parseText(xml);
return metadata[0].build;
}
@DisableCachingByDefault
abstract class EnigmaTask extends JavaExec {
@InputFile
abstract RegularFileProperty getJar()
@Input
abstract Property<File> getMappings()
EnigmaTask() {
classpath = project.configurations.enigmaRuntime
mainClass.set('cuchaz.enigma.gui.Main')
jvmArgs "-Xmx2048m"
}
@TaskAction
void exec() {
args '-jar'
args jar.get().asFile.absolutePath
args '-mappings'
args mappings.get().absolutePath
args '-profile'
args 'enigma_profile.json'
super.exec()
}
}
unifyMappings.configure {
tasks.each {task ->
if (task != it) {
it.mustRunAfter(task)
}
}
}