-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
build.gradle
519 lines (442 loc) · 15.8 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
buildscript {
repositories {
maven {
name 'Quilt Releases'
url 'https://maven.quiltmc.org/repository/release/'
}
maven {
name 'Quilt Snapshot Repository'
url 'https://maven.quiltmc.org/repository/snapshot/'
}
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
// remove when ASM fix is released
maven {
url = "https://repository.ow2.org/nexus/content/repositories/snapshots/"
}
mavenCentral()
mavenLocal()
}
dependencies {
classpath(libs.unpick)
classpath(libs.unpick.format.utils)
}
}
plugins {
id 'java' // for constants, packages, javadoc
id 'maven-publish'
id 'org.cadixdev.licenser' version '0.6.1'
id "mappings-logic"
}
def USE_SNAPSHOT_HASHES = false
def minecraft_version = Constants.MINECRAFT_VERSION
def ENV = System.getenv()
version = Constants.MAPPINGS_VERSION
if (ENV.BRANCH_NAME) {
def branch = ENV.BRANCH_NAME.substring(ENV.BRANCH_NAME.lastIndexOf('/') + 1)
if (minecraft_version != branch) {
throw new IllegalStateException("Branch name (${branch}) does not match the mc version (${minecraft_version})")
}
}
repositories {
maven {
name "Mojang"
url 'https://libraries.minecraft.net/'
}
mavenCentral()
maven {
name "Quilt Repository"
url "https://maven.quiltmc.org/repository/release"
}
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
maven {
name "Quilt Snapshot Repository"
url "https://maven.quiltmc.org/repository/snapshot"
}
// remove when ASM fix is released
maven {
url = "https://repository.ow2.org/nexus/content/repositories/snapshots/"
}
mavenLocal()
}
configurations {
enigmaRuntime
javadocClasspath
decompileClasspath
unpick
hashed
intermediary
}
dependencies {
enigmaRuntime(libs.enigma.swing)
enigmaRuntime(libs.enigma.plugin)
javadocClasspath(libs.quilt.loader)
javadocClasspath(libs.jetbrains.annotations)
javadocClasspath(libs.jsr305) // for some other jsr annotations
unpick(libs.unpick.cli)
hashed "org.quiltmc:hashed:${minecraft_version}${USE_SNAPSHOT_HASHES ? "-SNAPSHOT" : ""}"
intermediary "net.fabricmc:intermediary:${minecraft_version}:v2"
}
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.Opcodes
import org.quiltmc.draftsman.asm.visitor.DraftsmanAdapterClassVisitor
import quilt.internal.Constants
import quilt.internal.decompile.Decompilers
import quilt.internal.tasks.build.AddProposedMappingsTask
import quilt.internal.tasks.build.MappingsV2JarTask
import quilt.internal.tasks.build.TransformJarClassesTask
import quilt.internal.tasks.decompile.DecompileTask
import quilt.internal.tasks.jarmapping.MapPerVersionMappingsJarTask
import quilt.internal.tasks.mappings.EnigmaMappingsTask
import quilt.internal.tasks.unpick.RemapUnpickDefinitionsTask
import quilt.internal.tasks.unpick.UnpickJarTask
import quilt.internal.util.MappingsJavadocProvider
clean.doFirst {
delete mappings.fileConstants.tempDir, mappings.fileConstants.cacheFilesMinecraft,
mappings.fileConstants.unpickGlDefinitions, mappings.fileConstants.unpickGlStateManagerDefinitions
}
tasks.build.dependsOn "compressTiny", "tinyJar", "v2UnmergedMappingsJar", "v2MergedMappingsJar"
task insertAutoGeneratedMappings(dependsOn: [buildMappingsTiny, downloadPerVersionMappings], type: AddProposedMappingsTask) {
inputJar.set mappings.fileConstants.perVersionMappingsJar
inputMappings.set buildMappingsTiny.outputMappings
profile.set file("enigma_profile.json")
}
combineUnpickDefinitions {
input = mappings.fileConstants.unpickDefinitions
output = new File(mappings.fileConstants.buildDir, 'definitions.unpick')
}
def remappedDefinitions = new File(mappings.fileConstants.buildDir, Constants.PER_VERSION_MAPPINGS_NAME + '-definitions.unpick')
remapUnpickDefinitions {
dependsOn mergeTinyV2
output = remappedDefinitions
mappings = mergeTinyV2.outputMappings
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 21
}
sourceSets {
constants
packageDocs // package info files
doclet
}
license {
header file("HEADER")
include '**/*.java'
}
// Its artifact collides with the `tinyJar` one, just disable it since it isn't used either way
tasks.jar.enabled = false
task constantsJar(type: Jar) {
from sourceSets.constants.output
archiveClassifier = "constants"
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = "sources"
from sourceSets.constants.allSource
}
task unpickHashedJar(type: UnpickJarTask) {
inputFile.set mappings.fileConstants.perVersionMappingsJar
outputFile.set mappings.fileConstants.unpickedJar
unpickDefinition.set remapUnpickDefinitions.output.get()
unpickConstantsJar.set constantsJar.archiveFile
dependsOn MapPerVersionMappingsJarTask.TASK_NAME, "constantsJar", remapUnpickDefinitions
}
task mappingsUnpicked(type: EnigmaMappingsTask, dependsOn: unpickHashedJar) {
jarToMap.set unpickHashedJar.outputFile.get()
}
task mappings(type: EnigmaMappingsTask, dependsOn: "mapPerVersionMappingsJar") {
jarToMap.set mappings.fileConstants.perVersionMappingsJar
}
// Only build jars for package infos if we need to actually expose stuff like annotation in the future.
build.dependsOn constantsJar, generatePackageInfoMappings
task v2UnmergedMappingsJar(type: MappingsV2JarTask, dependsOn: [insertAutoGeneratedMappings, combineUnpickDefinitions]) {
archiveFileName = "${Constants.MAPPINGS_NAME}-${Constants.MAPPINGS_VERSION}-v2.jar"
mappings = insertAutoGeneratedMappings.outputMappings
}
task v2MergedMappingsJar(dependsOn: ["mergeTinyV2"], type: MappingsV2JarTask) {
archiveFileName = "${Constants.MAPPINGS_NAME}-${Constants.MAPPINGS_VERSION}-mergedv2.jar"
mappings = mergeTinyV2.outputMappings
}
task intermediaryV2MappingsJar(dependsOn: ["removeIntermediary"], type: MappingsV2JarTask) {
archiveFileName = "${Constants.MAPPINGS_NAME}-${Constants.MAPPINGS_VERSION}-intermediary-v2.jar"
mappings = removeIntermediary.outputMappings
onlyIf {
return checkIntermediaryMappings.isPresent()
}
}
task intermediaryV2MergedMappingsJar(dependsOn: ["mergeIntermediary"], type: MappingsV2JarTask) {
archiveFileName = "${Constants.MAPPINGS_NAME}-${Constants.MAPPINGS_VERSION}-intermediary-mergedv2.jar"
mappings = mergeIntermediary.outputMappings
onlyIf {
return checkIntermediaryMappings.isPresent()
}
}
task buildIntermediary {
dependsOn intermediaryV2MappingsJar, intermediaryV2MergedMappingsJar
onlyIf {
return checkIntermediaryMappings.isPresent()
}
}
task eraseBytecode(type: TransformJarClassesTask, dependsOn: mapNamedJar) {
jarFile = mappings.fileConstants.namedJar
output = file(".gradle/temp/erased-classes/")
visitor(DraftsmanAdapterClassVisitor::new)
// Set protected/package-private classes to public so that we don't have any access compile errors.
// TODO: Fix this by putting the classes in the same package. Javadoc shows the modifier
visitor { new ClassVisitor(Opcodes.ASM9, it) {
private int toPublicAccess(int access) {
if ((access & Opcodes.ACC_PROTECTED) != 0 || ((access & Opcodes.ACC_PRIVATE) == 0 && (access & Opcodes.ACC_PUBLIC) == 0)) {
access = access & ~Opcodes.ACC_PROTECTED
access = access | Opcodes.ACC_PUBLIC
}
return access
}
@Override
void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, toPublicAccess(access), name, signature, superName, interfaces)
}
@Override
void visitInnerClass(String name, String outerName, String innerName, int access) {
super.visitInnerClass(name, outerName, innerName, toPublicAccess(access))
}
} }
filter({ it.outerClass == null }) // filter out anonymous classes
}
def fakeSourceDir = file(".gradle/temp/fakeSource")
task genFakeSource(type: DecompileTask, dependsOn: [mergeTinyV2, eraseBytecode]) {
input = eraseBytecode.output.asFile.get()
output = fakeSourceDir
decompiler = Decompilers.VINEFLOWER
libraries = files(mappings.fileConstants.libraries)
decompilerOptions = [
"rsy": "1", // remove synthetics
"dgs": "1", // decompile generic signatures
"pll": "99999" // pll (Preferred Line Length) is length for line wrapping
]
// Tell gradle not to skip if the mappings file changed
inputs.file(mergeTinyV2.outputMappings)
doFirst {
fakeSourceDir.deleteDir()
def jdProvider = new MappingsJavadocProvider(mergeTinyV2.outputMappings, "named")
classJavadocProvider(jdProvider)
fieldJavadocProvider(jdProvider)
methodJavadocProvider(jdProvider)
}
doLast {
logger.lifecycle ":Fake source generated"
}
}
task decompileVineflower(type: DecompileTask, dependsOn: [mapNamedJar]) {
input.set mappings.fileConstants.namedJar
output.set file("namedSrc")
decompiler = Decompilers.VINEFLOWER
libraries = files(configurations.decompileClasspath)
doFirst {
file("namedSrc").deleteDir()
def javadocProvider = new MappingsJavadocProvider(insertAutoGeneratedMappings.outputMappings, "named")
classJavadocProvider(javadocProvider)
fieldJavadocProvider(javadocProvider)
methodJavadocProvider(javadocProvider)
}
}
task remapTargetUnpickDefinitions(type: RemapUnpickDefinitionsTask) {
dependsOn "checkUnpickVersionsMatch", "downloadTargetMappingsJar"
output.set downloadTargetMappingsJar.targetUnpickRemappedDefinitionsFile
mappings.set downloadTargetMappingsJar.targetMappingsFile
input.set downloadTargetMappingsJar.targetUnpickDefinitionsFile
onlyIf {
checkUnpickVersionsMatch.match
}
}
task unpickTargetJar(type: UnpickJarTask) {
dependsOn "checkUnpickVersionsMatch", "downloadMinecraftLibraries", "remapTargetUnpickDefinitions", "mapPerVersionMappingsJar"
inputFile.set mappings.fileConstants.perVersionMappingsJar
outputFile.set remapTargetMinecraftJar.inputJar
unpickDefinition.set remapTargetUnpickDefinitions.output
unpickConstantsJar.set downloadTargetMappingsJar.targetUnpickConstantsFile
onlyIf {
checkUnpickVersionsMatch.match
}
}
task decompileTargetVineflower(type: DecompileTask, dependsOn: [remapTargetMinecraftJar]) {
input.set remapTargetMinecraftJar.outputJar
output.set file("namedTargetSrc")
decompiler = Decompilers.VINEFLOWER
libraries = files(configurations.decompileClasspath)
doFirst {
file("namedTargetSrc").deleteDir()
def javadocProvider = new MappingsJavadocProvider(downloadTargetMappingsJar.targetMappingsFile.get().getAsFile(), "named")
classJavadocProvider(javadocProvider)
fieldJavadocProvider(javadocProvider)
methodJavadocProvider(javadocProvider)
}
onlyIf {
checkUnpickVersionsMatch.match
}
}
javadoc {
dependsOn genFakeSource
dependsOn downloadMinecraftLibraries
dependsOn docletClasses // Needed for javadoc to find the doclet classes.
group = "javadoc generation"
outputs.upToDateWhen { false }
destinationDir = file("${buildDir}/docs/${project.version}")
def docletResources = sourceSets.doclet.resources.asFileTree
failOnError = true // Failing on error is important to ensure that a Javadoc jar is available.
maxMemory = '2G'
// verbose = true // enable to debug
options {
// verbose() // enable to debug
source = "21"
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 "quilt.internal.taglet.MappingTaglet"
// taglet path, header, extra stylesheet settings deferred
it.use()
addBooleanOption "-allow-script-in-comments", true
links(
"https://javadoc.io/doc/com.google.guava/guava/${libs.versions.guava.get()}/",
"https://javadoc.io/doc/com.google.code.gson/gson/${project.gson}/",
"https://javadoc.io/doc/org.jetbrains/annotations/${libs.versions.jetbrains.annotations.get()}/",
"https://javadoc.io/doc/com.google.code.findbugs/jsr305/${libs.versions.jsr305.get()}/",
"https://javadoc.io/doc/org.apache.commons/commons-compress/${project.commons_compress}/",
"https://javadoc.io/doc/io.netty/netty-all/${project.netty}/",
'https://javadoc.lwjgl.org/',
'https://logging.apache.org/log4j/2.x/javadoc/log4j-api/',
'https://fastutil.di.unimi.it/docs/',
"https://commons.apache.org/proper/commons-logging/javadocs/api-release/",
"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/${project.commons_codec}/apidocs/",
"https://javadoc.quiltmc.org/quilt-loader/${libs.versions.quilt.loader.get()}/",
"https://docs.oracle.com/en/java/javase/${project.java}/docs/api/"
)
// https://docs.oracle.com/en/java/javase/21/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
addStringOption '-notimestamp'
}
source fileTree(fakeSourceDir) + sourceSets.constants.allJava + sourceSets.packageDocs.allJava
classpath = configurations.javadocClasspath + downloadMinecraftLibraries.outputs.files.asFileTree + mapNamedJar.outputs.files.asFileTree
doLast {
project.copy {
from docletResources
include "copy_on_click.js"
into javadoc.outputDirectory
}
}
doFirst {
// lazy setting
options {
tagletPath sourceSets.doclet.output.classesDirs.files.toList()
header docletResources.filter { it.name == 'javadoc_header.txt' }.singleFile.text.trim()
addFileOption "-add-stylesheet", docletResources.filter { it.name == 'style.css' }.singleFile
}
}
}
task javadocJar(type: Jar, dependsOn: ["javadoc"]) {
group = "javadoc generation"
from javadoc.destinationDir
archiveVersion.set Constants.MAPPINGS_VERSION
archiveClassifier = 'javadoc'
}
generatePackageInfoMappings {
packageName = "net/minecraft/unused/packageinfo/"
}
mappingLint {
dependsOn mapPerVersionMappingsJar
mappingDirectory = file("mappings")
jarFile = mappings.fileConstants.perVersionMappingsJar
}
check.dependsOn mappingLint
publishing {
publications {
maven(MavenPublication) {
groupId 'org.quiltmc'
artifactId Constants.MAPPINGS_NAME
version Constants.MAPPINGS_VERSION
// quilt-mappings-<version>-tiny.gz
artifact(compressTiny.compressedTiny) {
classifier "tiny"
builtBy compressTiny
}
// quilt-mappings-<version>.jar
artifact(tinyJar)
// quilt-mappings-<version>-v2.jar
artifact(v2UnmergedMappingsJar) {
classifier "v2"
}
// quilt-mappings-<version>-mergedv2.jar
artifact(v2MergedMappingsJar) {
classifier "mergedv2"
}
// quilt-mappings-<version>-constants.jar
artifact(constantsJar) {
classifier "constants"
}
// quilt-mappings-<version>-sources.jar
artifact sourcesJar
// quilt-mappings-<version>-javadoc.jar
artifact javadocJar
// See below the publishing block for intermediary artifact publishing
}
}
repositories {
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
} else if (USE_SNAPSHOT_HASHES && ENV.SNAPSHOTS_URL) {
maven {
url = ENV.SNAPSHOTS_URL
credentials {
username = ENV.SNAPSHOTS_USERNAME
password = ENV.SNAPSHOTS_PASSWORD
}
}
}
mavenLocal()
}
}
tasks.withType(AbstractPublishToMaven).all { AbstractPublishToMaven t ->
// Won't run if checkIntermediaryMappings returns false
dependsOn buildIntermediary
doFirst {
if (checkIntermediaryMappings.isPresent()) {
MavenPublication p = it.publication
def addArtifact = { Task task, String artifactClassifier ->
if (p.getArtifacts().findAll {a -> a.getClassifier() == artifactClassifier }.isEmpty()) {
p.artifact(task) {
classifier artifactClassifier
}
}
}
// quilt-mappings-<version>-intermediary-v2.jar
addArtifact(intermediaryV2MappingsJar, "intermediary-v2")
// quilt-mappings-<version>-intermediary-mergedv2.jar
addArtifact(intermediaryV2MergedMappingsJar, "intermediary-mergedv2")
}
}
}