forked from MinecraftForge/MinecraftForge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
942 lines (800 loc) · 35.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
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
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
import net.minecraftforge.gradle.userdev.tasks.RenameJar
import net.minecraftforge.gradleutils.GradleUtils
import net.minecraftforge.srgutils.IMappingFile
import java.nio.file.Files
import net.minecraftforge.forge.tasks.*
import net.minecraftforge.forge.tasks.checks.*
import static net.minecraftforge.forge.tasks.Util.*
import net.minecraftforge.gradle.common.tasks.CheckJarCompatibility
import net.minecraftforge.gradle.common.tasks.DownloadMavenArtifact
import net.minecraftforge.gradle.common.tasks.ExtractInheritance
import net.minecraftforge.gradle.common.tasks.SignJar
import net.minecraftforge.gradle.common.tasks.ApplyBinPatches
import net.minecraftforge.gradle.common.tasks.ExtractMCPData
import net.minecraftforge.gradle.patcher.tasks.GenerateBinPatches
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.apache.commons.compress.compressors.lzma.LZMACompressorOutputStream
plugins {
id 'org.cadixdev.licenser' version '0.6.1'
id 'net.minecraftforge.gradleutils' version '2.+'
id 'eclipse'
id 'de.undercouch.download' version '5.4.0'
id 'net.minecraftforge.gradle.patcher' version '[5.1.50,5.2.0)' apply false
id 'net.minecraftforge.gradle.mcp' version '[5.1.50,5.2.0)' apply false
}
Util.init() //Init all our extension methods!
//------------------------------------------------------------------------------------------------------------------------------------------
// Configuration
//------------------------------------------------------------------------------------------------------------------------------------------
ext {
JAR_SIGNER = null
if (project.hasProperty('keystore')) {
JAR_SIGNER = [
storepass: project.properties.keystoreStorePass,
keypass: project.properties.keystoreKeyPass,
keystore: project.properties.keystore
]
}
MAPPING_CHANNEL = 'snapshot_nodoc'
MAPPING_VERSION = '20161220-1.11'
MC_VERSION = '1.11.2'
MCP_VERSION = '20210824.173128'
POST_PROCESSOR = [
tool: 'net.minecraftforge:mcpcleanup:2.3.6:fatjar',
repo: 'https://maven.minecraftforge.net/',
args: ['--input', '{input}', '--output', '{output}', '--fix-generic-params']
]
MERGETOOL_VERSION = '0.2.3.3'
INSTALLER_VERSION = '2.1.+'
GIT_INFO = gradleutils.gitInfo
}
//------------------------------------------------------------------------------------------------------------------------------------------
// RetroGradle
//------------------------------------------------------------------------------------------------------------------------------------------
apply from: 'retrogradle-dev.gradle'
ext {
LEGACY_MAJOR = 13 // Legacy versions have an API change prefix
LEGACY_BUILD = 2588 // Base build number to not conflict with existing build numbers
BUILD_NUMBER = LEGACY_BUILD + (GIT_INFO.offset as int) // LEGACY_BUILD + commit offset, used to mimic unique build from old versions
SPEC_VERSION = '20.1' // This is overwritten by git tag, but here so dev time doesn't explode
VERSION = GradleUtils.getMCTagOffsetBranchVersion(GIT_INFO + [tag: "${LEGACY_MAJOR}.${SPEC_VERSION}", offset: BUILD_NUMBER], MC_VERSION)
FORGE_VERSION = VERSION.substring(MC_VERSION.length() + 1)
MIN_TAG_FOR_CHANGELOG = '20.0'
}
println('Version: ' + VERSION +
' Java: ' + System.getProperty('java.version') +
' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ')' +
' Arch: ' + System.getProperty('os.arch'))
// TODO RG: Enable changelog
// changelog {
// fromTag MIN_TAG_FOR_CHANGELOG
// }
//--------------------------------------------------------------------------------------------------------------------------------------
// Extra text files for installer
//--------------------------------------------------------------------------------------------------------------------------------------
def extraTxts = [
rootProject.file('CREDITS.txt'),
rootProject.file('LICENSE.txt'),
rootProject.file('LICENSE-Paulscode IBXM Library.txt'),
rootProject.file('LICENSE-Paulscode SoundSystem CodecIBXM.txt')
]
if (rootProject.tasks.findByName('createChangelog'))
extraTxts.add rootProject.tasks.createChangelog.outputFile
subprojects {
apply plugin: 'maven-publish'
apply plugin: 'eclipse'
apply plugin: 'java'
group = 'net.minecraftforge'
version = VERSION
repositories {
mavenLocal()
mavenCentral()
maven {
name = 'forge'
url = 'https://maven.minecraftforge.net/'
}
maven {
name = 'minecraft'
url = 'https://libraries.minecraft.net/'
}
}
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
tasks.withType(Javadoc).configureEach {
options.tags = [
'apiNote:a:<em>API Note:</em>',
'implSpec:a:<em>Implementation Requirements:</em>',
'implNote:a:<em>Implementation Note:</em>'
]
options.addStringOption('Xdoclint:all,-missing', '-public')
}
publishing {
publications {
mavenJava(MavenPublication) {
// Normal Maven/old gradle doesn't support '2.+' version wildcards
// For now we just suppress. We *should* force the resolution to pinned versions.
suppressPomMetadataWarningsFor('apiElements')
suppressPomMetadataWarningsFor('runtimeElements')
pom {
name = project.name
description = 'Modifactions to Minecraft to enable mod developers.'
url = 'https://github.com/MinecraftForge/MinecraftForge'
scm {
url = 'https://github.com/MinecraftForge/MinecraftForge'
connection = 'scm:git:git://github.com/MinecraftForge/MinecraftForge.git'
developerConnection = 'scm:git:[email protected]:MinecraftForge/MinecraftForge.git'
}
issueManagement {
system = 'github'
url = 'https://github.com/MinecraftForge/MinecraftForge/issues'
}
licenses {
license {
name = 'LGPL 2.1'
url = 'https://github.com/MinecraftForge/MinecraftForge/blob/1.13-pre/LICENSE.txt'
distribution = 'repo'
}
}
}
}
}
repositories {
maven gradleutils.getPublishingForgeMaven()
}
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
// MCP
//------------------------------------------------------------------------------------------------------------------------------------------
project(':mcp') {
apply plugin: 'net.minecraftforge.gradle.mcp'
tasks.withType(AbstractPublishToMaven.class).forEach{tsk -> tsk.enabled = false } // We don't want to publish anything
mcp {
config MC_VERSION + '-' + MCP_VERSION
pipeline = 'joined'
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
// Clean
//------------------------------------------------------------------------------------------------------------------------------------------
project(':clean') {
evaluationDependsOn(':mcp')
apply plugin: 'net.minecraftforge.gradle.patcher'
apply plugin: 'idea'
tasks.withType(AbstractPublishToMaven.class).forEach{tsk -> tsk.enabled = false } // We don't want to publish anything
idea {
module {
// Fix resource loading with older FML versions that relied on a unified output folder
inheritOutputDirs = true
}
}
sourceSets.all {
output.resourcesDir = java.destinationDirectory
}
dependencies {
implementation "net.minecraftforge:mergetool:${MERGETOOL_VERSION}:forge"
}
patcher {
parent = project(':mcp')
mcVersion = MC_VERSION
patchedSrc = file('src/main/java')
mappings channel: MAPPING_CHANNEL, version: MAPPING_VERSION
processor = POST_PROCESSOR
runs {
clean_client {
client true
taskName 'clean_client'
ideaModule "${rootProject.name}.${project.name}.main"
main 'net.minecraft.client.main.Main'
workingDirectory project.file('run')
args '--gameDir', '.'
args '--version', MC_VERSION
args '--assetsDir', downloadAssets.output
args '--assetIndex', '{asset_index}'
args '--accessToken', '0'
}
clean_server {
client false
taskName 'clean_server'
ideaModule "${rootProject.name}.${project.name}.main"
main 'net.minecraft.server.MinecraftServer'
workingDirectory project.file('run')
}
}
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
// Forge
//------------------------------------------------------------------------------------------------------------------------------------------
project(':forge') {
evaluationDependsOn(':clean')
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'net.minecraftforge.gradle.patcher'
apply plugin: 'org.cadixdev.licenser'
idea {
module {
// Fix resource loading with older FML versions that relied on a unified output folder
inheritOutputDirs = true
}
}
sourceSets {
main {
java {
srcDirs = ["$rootDir/src/main/java"]
}
resources {
srcDirs = ["$rootDir/src/main/resources"]
}
}
test {
java {
srcDirs = ["$rootDir/src/test/java"]
}
resources {
srcDirs = ["$rootDir/src/test/resources"]
}
}
all {
output.resourcesDir = java.destinationDirectory
}
}
//Eclipse adds the sourcesets twice, once where we tell it to, once in the projects folder. No idea why. So delete them
eclipse.classpath.file.whenMerged { cls -> cls.entries.removeIf { e -> e instanceof SourceFolder && e.path.startsWith('src/') && !e.path.startsWith('src/main/') } }
ext {
MCP_ARTIFACT = project(':mcp').mcp.config.get()
SPECIAL_SOURCE = 'net.md-5:SpecialSource:1.11.0:shaded'
VERSION_JSON = project(':mcp').file('build/mcp/downloadJson/version.json')
BINPATCH_TOOL = 'net.minecraftforge:binarypatcher:1.1.1:fatjar'
INSTALLER_TOOLS = 'net.minecraftforge:installertools:1.1.11'
}
// compileJava {
// javaCompiler = javaToolchains.compilerFor {
// languageVersion = JavaLanguageVersion.of(7)
// }
// }
//--------------------------------------------------------------------------------------------------------------------------------------
// Dependencies
//--------------------------------------------------------------------------------------------------------------------------------------
configurations {
installer {
// Don't pull all libraries, if we're missing something, add it to the installer list so the installer knows to download it.
transitive = false
}
api.extendsFrom(installer)
}
dependencies {
installer 'org.ow2.asm:asm-debug-all:5.2'
installer 'net.minecraft:launchwrapper:1.12'
installer 'com.typesafe.akka:akka-actor_2.11:2.3.3'
installer 'com.typesafe:config:1.2.1'
installer 'org.scala-lang:scala-actors-migration_2.11:1.1.0'
installer 'org.scala-lang:scala-compiler:2.11.1'
installer 'org.scala-lang.plugins:scala-continuations-library_2.11:1.0.2_mc' //We change the version so old installs don't break, as our clone of the jar is different the maven central
installer 'org.scala-lang.plugins:scala-continuations-plugin_2.11.1:1.0.2_mc' // --^
installer 'org.scala-lang:scala-library:2.11.1'
installer 'org.scala-lang:scala-parser-combinators_2.11:1.0.1'
installer 'org.scala-lang:scala-reflect:2.11.1'
installer 'org.scala-lang:scala-swing_2.11:1.0.1'
installer 'org.scala-lang:scala-xml_2.11:1.0.2'
installer 'lzma:lzma:0.0.1'
installer 'java3d:vecmath:1.5.2'
installer 'net.sf.trove4j:trove4j:3.0.3'
installer 'org.apache.maven:maven-artifact:3.5.3'
installer 'net.sf.jopt-simple:jopt-simple:5.0.3'
installer 'jline:jline:2.13'
implementation 'net.minecraftforge:legacydev:0.2.3.+:fatjar'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.+'
testImplementation 'org.opentest4j:opentest4j:1.0.0' // needed for junit 5
testImplementation 'org.hamcrest:hamcrest-all:1.3' // needs advanced matching for list order
}
//--------------------------------------------------------------------------------------------------------------------------------------
// Setup
//--------------------------------------------------------------------------------------------------------------------------------------
patcher {
excs.from file("$rootDir/src/main/resources/forge.exc")
parent = project(':clean')
patches = file("$rootDir/patches/minecraft")
patchedSrc = file('src/main/java')
srgPatches = true
notchObf = true
accessTransformers.from file("$rootDir/src/main/resources/forge_at.cfg")
// sideAnnotationStripper.from file("$rootDir/src/main/resources/forge.sas")
processor = POST_PROCESSOR
//----------------------------------------------------------------------------------------------------------------------------------
// Run Configurations
//----------------------------------------------------------------------------------------------------------------------------------
runs {
forge_client {
client true
main 'net.minecraftforge.legacydev.MainClient'
environment 'target', 'fmldevclient'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLTweaker'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', downloadAssets.output
environment 'nativesDirectory', extractNatives.output.get().asFile
mods {
forge { source sourceSets.main }
}
}
forge_test_client {
parent runs.forge_client
environment 'MOD_CLASSES', 'dummy' // Needed to work around FG limitation, FG will replace this!
ideaModule "${rootProject.name}.${project.name}.test"
mods {
tests { sources sourceSets.test }
}
}
forge_server {
client false
main 'net.minecraftforge.legacydev.MainServer'
environment 'target', 'fmldevserver'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLServerTweaker'
mods {
forge { source sourceSets.main }
}
}
forge_test_server {
parent runs.forge_server
environment 'MOD_CLASSES', 'dummy' // Needed to work around FG limitation, FG will replace this!
ideaModule "${rootProject.name}.${project.name}.test"
mods {
tests { sources sourceSets.test }
}
}
}
for (def run : runs) {
if (run.parents) continue // We already added this to the parent run config
run.workingDirectory project.file('run')
run.ideaModule "${rootProject.name}.${project.name}.main"
run.environment 'mainClass', 'net.minecraft.launchwrapper.Launch'
run.environment 'MC_VERSION', MC_VERSION
run.environment 'MCP_VERSION', MCP_VERSION
run.environment 'MCP_TO_SRG', createSrg2Mcp.getOutput().get().getAsFile().getAbsolutePath()
run.environment 'FORGE_GROUP', project.group
run.environment 'FORGE_VERSION', FORGE_VERSION
}
}
//--------------------------------------------------------------------------------------------------------------------------------------
// Manifest
//--------------------------------------------------------------------------------------------------------------------------------------
ext {
MANIFESTS = [
'/': [
'Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'GitCommit': GIT_INFO.abbreviatedId,
'Git-Branch': GIT_INFO.branch
] as LinkedHashMap,
'net/minecraftforge/common/': [
'Specification-Title': 'Forge',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': SPEC_VERSION,
'Implementation-Title': project.group,
'Implementation-Version': FORGE_VERSION,
'Implementation-Vendor': 'Forge Development LLC'
] as LinkedHashMap
]
}
//--------------------------------------------------------------------------------------------------------------------------------------
// Bin Patch Generation
//--------------------------------------------------------------------------------------------------------------------------------------
// We apply the bin patches we just created to make a jar that is JUST our changes
['Client', 'Server', 'Joined'].each { side ->
def gen = tasks.getByName("gen${side}BinPatches")
gen.tool = BINPATCH_TOOL
task "apply${side}BinPatches"(type: ApplyBinPatches, dependsOn: gen) {
clean = gen.cleanJar
patch = gen.output
tool = BINPATCH_TOOL
}
}
task genRuntimeBinPatches(type: GenerateBinPatches, dependsOn: [genClientBinPatches, genServerBinPatches]) {
tool = BINPATCH_TOOL
cleanJar = genClientBinPatches.cleanJar
dirtyJar = genClientBinPatches.dirtyJar
srg = genClientBinPatches.srg
patchSets.setFrom(genClientBinPatches.patchSets)
afterEvaluate {
getArgs().set([
'--output', '{output}',
'--patches', '{patches}',
'--srg', '{srg}',
'--legacy',
'--clean', '{clean}',
'--dirty', '{dirty}',
'--prefix', 'binpatch/client',
'--clean', genServerBinPatches.cleanJar.get().asFile.absolutePath,
'--dirty', genServerBinPatches.dirtyJar.get().asFile.absolutePath,
'--prefix', 'binpatch/server'
])
}
}
task downloadLibraries(type: DownloadLibraries, dependsOn: ':mcp:setupMCP') {
input = VERSION_JSON
output = rootProject.file('build/libraries/')
}
task extractInheritance(type: ExtractInheritance, dependsOn: [genJoinedBinPatches, downloadLibraries]) {
tool = INSTALLER_TOOLS + ':fatjar'
// args.add '--annotations'
input = genJoinedBinPatches.cleanJar
libraries.addAll downloadLibraries.librariesOutput.map { rf -> Files.readAllLines(rf.asFile.toPath()).stream().map(File::new).collect(java.util.stream.Collectors.toList()) }
}
tasks.register('checkAll') {
dependsOn 'checkLicenses'
group = 'checks'
}
tasks.register('checkAllAndFix') {
dependsOn 'findFieldInstanceChecks', 'checkLicenses'
group = 'checks'
}
CheckTask.registerTask(tasks, 'ATs', CheckATs) {
dependsOn extractInheritance, createSrg2Mcp
ats.from patcher.accessTransformers
inheritance = extractInheritance.output
mappings = createSrg2Mcp.output
}
CheckTask.registerTask(tasks, 'SAS', CheckSAS) {
dependsOn extractInheritance
sass.from patcher.sideAnnotationStrippers
inheritance = extractInheritance.output
}
CheckTask.registerTask(tasks, 'Excs', CheckExcs) {
dependsOn jar
binary = jar.archiveFile.get().asFile
excs.from patcher.excs
}
CheckTask.registerTask(tasks, 'Patches', CheckPatches) {
dependsOn genPatches
patchDir = file("$rootDir/patches")
patchesWithS2SArtifact = [
'minecraft/net/minecraft/client/renderer/ViewArea.java.patch',
'minecraft/net/minecraft/data/models/blockstates/Variant.java.patch',
]
}
//--------------------------------------------------------------------------------------------------------------------------------------
// Patches
//--------------------------------------------------------------------------------------------------------------------------------------
applyPatches {
originalPrefix = '../src-base/minecraft/'
modifiedPrefix = '../src-work/minecraft/'
}
genPatches {
finalizedBy checkAndFixPatches
autoHeader false
lineEnding = '\n'
originalPrefix = '../src-base/minecraft/'
modifiedPrefix = '../src-work/minecraft/'
}
def baseForgeVersionProperty = project.objects.property(String)
baseForgeVersionProperty.set(project.provider { getLatestForgeVersion(MC_VERSION) }.map { MC_VERSION + '-' + it })
baseForgeVersionProperty.finalizeValueOnRead()
def jarCompatibilityTaskSetup = { task ->
task.group = 'jar compatibility'
task.onlyIf {
baseForgeVersionProperty.getOrNull() != null
}
}
tasks.register('setupCheckJarCompatibility', SetupCheckJarCompatibility) {
inputVersion = baseForgeVersionProperty
}
tasks.register('applyBaseCompatibilityJarBinPatches', ApplyBinPatches) {
jarCompatibilityTaskSetup(it)
clean = project.tasks.named('genJoinedBinPatches').flatMap { it.cleanJar }
patch = project.tasks.named('setupCheckJarCompatibility').flatMap { it.baseBinPatchesOutput }
output = project.layout.buildDirectory.dir(name).map { it.file('output.jar') }
args.add '--unpatched'
}
tasks.register('downloadBaseForgeJar', Download) {
jarCompatibilityTaskSetup(it)
src baseForgeVersionProperty.map {"https://maven.minecraftforge.net/net/minecraftforge/forge/${it}/forge-${it}-universal.jar" }
dest project.layout.buildDirectory.dir(name).map { it.file('output.jar') }
}
tasks.register('mergeBaseForgeJar', MergeJars) {
jarCompatibilityTaskSetup(it)
inputJars.from(project.tasks.named('applyBaseCompatibilityJarBinPatches').flatMap { it.output })
inputJars.from(project.tasks.named('downloadBaseForgeJar').map { it.dest })
}
tasks.register('deobfMergedBaseForgeJar', RenameJar) {
jarCompatibilityTaskSetup(it)
// This won't be a perfect deobfuscation because we don't provide inheritance data, but it should be good enough for compatibility checking
tool = SPECIAL_SOURCE
args = [
'--in-jar', '{input}',
'--out-jar', '{output}',
'--srg-in', '{mappings}',
'--live'
]
mappings = tasks.named('extractObf2Srg').flatMap { it.output }
input = project.tasks.named('mergeBaseForgeJar').flatMap { it.output }
output = project.layout.buildDirectory.dir(name).map { it.file('output.jar') }
}
tasks.register('deobfReobfJar', RenameJar) {
jarCompatibilityTaskSetup(it)
// This won't be a perfect deobfuscation because we don't provide inheritance data, but it should be good enough for compatibility checking
tool = SPECIAL_SOURCE
args = [
'--in-jar', '{input}',
'--out-jar', '{output}',
'--srg-in', '{mappings}'
]
mappings = tasks.named('extractObf2Srg').flatMap { it.output }
input = project.tasks.named('reobfJar').flatMap { it.output }
output = project.layout.buildDirectory.dir(name).map { it.file('output.jar') }
}
tasks.register('checkJarCompatibility', CheckJarCompatibility) {
jarCompatibilityTaskSetup(it)
dependsOn 'setupCheckJarCompatibility'
baseJar = project.tasks.named('deobfMergedBaseForgeJar').flatMap { it.output }
inputJar = project.tasks.named('deobfReobfJar').flatMap { it.output }
commonLibraries.from(project.configurations.minecraftImplementation)
commonLibraries.from(project.configurations.installer)
}
task launcherJson(type: LauncherJson) {
doFirst {
json = [
_comment_: comment,
id: id,
time: timestamp,
releaseTime: timestamp,
type: 'release',
mainClass: 'net.minecraft.launchwrapper.Launch',
inheritsFrom: MC_VERSION,
logging: {},
minecraftArguments: [
'--username', '${auth_player_name}',
'--version', '${version_name}',
'--gameDir', '${game_directory}',
'--assetsDir', '${assets_root}',
'--assetIndex', '${assets_index_name}',
'--uuid', '${auth_uuid}',
'--accessToken', '${auth_access_token}',
'--userType', '${user_type}',
'--tweakClass', 'net.minecraftforge.fml.common.launcher.FMLTweaker',
'--versionType', 'Forge'
].join(' '),
libraries: []
]
}
}
task installerJson(type: InstallerJson, dependsOn: [launcherJson, genClientBinPatches, applyClientBinPatches, applyServerBinPatches, 'signUniversalJar']) {
input.from applyClientBinPatches.output, applyServerBinPatches.output, genClientBinPatches.toolJar, launcherJson.output
icon = rootProject.file('icon.ico')
doFirst {
def libs = libraries
json = [
_comment_: launcherJson.comment,
spec: 0,
profile: project.name,
version: launcherJson.id,
path: "${project.group}:${project.name}:${project.version}:universal",
minecraft: MC_VERSION,
data: [:],
processors: []
]
getClasspath(project, libs, MCP_ARTIFACT.descriptor) //Tell it to download mcp_config
}
}
task extractObf2Srg(type: ExtractMCPData, dependsOn: [':mcp:downloadConfig']) {
config = project(':mcp').downloadConfig.output
}
task deobfDataLzma(dependsOn: [extractObf2Srg]) {
ext {
output_srg = file('build/deobfDataLzma/data.srg')
output = file('build/deobfDataLzma/data.lzma')
}
doLast {
IMappingFile.load(extractObf2Srg.output.get().getAsFile()).write(output_srg.toPath(), IMappingFile.Format.SRG, false)
output_srg.withInputStream { ins ->
output.withOutputStream { outs ->
def lz = new LZMACompressorOutputStream(outs)
def i = -1
def buf = new byte[0x100]
while ((i = ins.read(buf)) != -1)
lz.write(buf, 0, i)
lz.close()
}
}
}
}
universalJar {
from(extraTxts)
dependsOn(deobfDataLzma)
from(deobfDataLzma.output) {
rename { "deobfuscation_data-${MC_VERSION}.lzma" }
}
dependsOn(genRuntimeBinPatches)
from(genRuntimeBinPatches.output) {
rename { 'binpatches.pack.lzma' }
}
doFirst {
def classpath = new StringBuilder()
def artifacts = getArtifacts(project, project.configurations.installer, false)
artifacts.each { key, lib ->
classpath.append("libraries/${lib.downloads.artifact.path} ")
}
classpath += "minecraft_server.${MC_VERSION}.jar"
MANIFESTS.each { pkg, values ->
if (pkg == '/') {
manifest.attributes(values += [
'Main-Class': 'net.minecraftforge.fml.relauncher.ServerLaunchWrapper',
'Class-Path': classpath.toString(),
'Tweak-Class': 'net.minecraftforge.fml.common.launcher.FMLTweaker'
])
} else {
manifest.attributes(values, pkg)
}
}
}
}
task downloadInstaller(type: DownloadMavenArtifact) {
artifact = "net.minecraftforge:installer:${INSTALLER_VERSION}:shrunk"
changing = true
}
task installerJar(type: InstallerJar, dependsOn: [genClientBinPatches, genServerBinPatches, 'signUniversalJar', launcherJson]) {
from(extraTxts)
from(rootProject.file('/src/main/resources/forge_logo.png')) {
rename { 'big_logo.png' }
}
}
[tasks.universalJar, tasks.installerJar].each { t ->
def signTask = task "sign${t.name.capitalize()}"([type: SignJar, dependsOn: t]) {
onlyIf {
JAR_SIGNER != null && t.state.failure == null
}
def jarsigner = JAR_SIGNER == null ? [:] : JAR_SIGNER
alias = 'forge'
storePass = jarsigner.storepass
keyPass = jarsigner.keypass
keyStore = jarsigner.keystore
inputFile = t.archiveFile.get().asFile
outputFile = t.archiveFile.get().asFile
doFirst {
project.logger.lifecycle('Signing: ' + inputFile)
}
}
t.finalizedBy(signTask)
}
task makeMdk(type: Zip) {
archiveBaseName = project.name
archiveClassifier = 'mdk'
archiveVersion = project.version
destinationDirectory = file('build/libs')
from rootProject.file('gradlew')
from rootProject.file('gradlew.bat')
from extraTxts
from(rootProject.file('gradle/')) {
into('gradle/')
}
from(rootProject.file('mdk/')) {
rootProject.file('mdk/gitignore.txt').eachLine {
if (!it.trim().isEmpty() && !it.trim().startsWith('#'))
exclude it
}
filter(ReplaceTokens, tokens: [
FORGE_VERSION: project.version,
FORGE_GROUP: project.group,
FORGE_NAME: project.name,
MC_VERSION: MC_VERSION,
MAPPING_CHANNEL: MAPPING_CHANNEL,
MAPPING_VERSION: MAPPING_VERSION
])
rename 'gitignore\\.txt', '.gitignore'
}
}
userdevConfig {
def artifacts = getArtifacts(project, project.configurations.installer, true)
artifacts.each { key, lib ->
libraries.add(lib.name)
}
libraries.add('net.minecraftforge:legacydev:0.2.3.+:fatjar')
universalFilters.add('^(?!binpatches\\.pack\\.lzma$).*$')
runs {
client {
main 'net.minecraftforge.legacydev.MainClient'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLTweaker'
environment 'mainClass', 'net.minecraft.launchwrapper.Launch'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', '{assets_root}'
environment 'nativesDirectory', '{natives}'
environment 'MC_VERSION', MC_VERSION
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'MCP_TO_SRG', '{mcp_to_srg}'
environment 'FORGE_GROUP', project.group
environment 'FORGE_VERSION', FORGE_VERSION
}
server {
main 'net.minecraftforge.legacydev.MainServer'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLServerTweaker'
environment 'mainClass', 'net.minecraft.launchwrapper.Launch'
environment 'MC_VERSION', MC_VERSION
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'MCP_TO_SRG', '{mcp_to_srg}'
environment 'FORGE_GROUP', project.group
environment 'FORGE_VERSION', FORGE_VERSION
}
}
}
userdevJar {
classifier 'userdev3' // Should be 'userdev', but FG5 hardcodes pre 1.13 versions to 'userdev3'
}
reobfJar {
args.addAll('--srg-in', rootProject.file('src/main/resources/forge.srg').absolutePath)
}
tasks.eclipse.dependsOn('genEclipseRuns')
if (project.hasProperty('UPDATE_MAPPINGS')) {
extractRangeMap {
sources.from sourceSets.test.java.srcDirs
addDependencies compileTestJava.classpath
}
applyRangeMap {
sources.from sourceSets.test.java.srcDirs
}
sourceSets.test.java.srcDirs.each { extractMappedNew.addTarget it }
}
tasks.named('javadoc', Javadoc).configure {
description 'Generates the combined javadocs for the FML projects and the main Forge project'
var docsDir = rootProject.file('src/docs/')
inputs.dir(docsDir)
.withPropertyName('docs resources directory')
.withPathSensitivity(PathSensitivity.RELATIVE)
.optional()
failOnError = false
// Exclude the Minecraft classes if not enabled
if (!project.hasProperty('generateAllDocumentation')) {
exclude 'net/minecraft/**'
exclude 'com/mojang/**'
}
exclude 'mcp/**'
options.addStringOption('Xdoclint:all,-missing', '-public')
options {
stylesheetFile = new File(docsDir, 'stylesheet.css')
tags = [
'apiNote:a:<em>API Note:</em>',
'implSpec:a:<em>Implementation Requirements:</em>',
'implNote:a:<em>Implementation Note:</em>'
]
groups = [
'Forge Mod Loader': [
'net.minecraftforge.fml*'
],
'Minecraft Forge API': [
'net.minecraftforge*'
]
]
author = false
noSince = true
noHelp = true
bottom = "Minecraft Forge is an open source modding API for Minecraft: Java Edition, licensed under the Lesser GNU General Public License, version 2.1."
windowTitle = "Minecraft Forge API ${VERSION}"
docTitle = "Minecraft Forge API - ${FORGE_VERSION} for Minecraft ${MC_VERSION}"
header = "<div style=\"margin-top: 9px;padding: 5px 6px;\"><strong>${FORGE_VERSION} for Minecraft ${MC_VERSION}</strong></div>"
}
doLast {
project.copy {
from docsDir
exclude '/stylesheet.css'
into destinationDir
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact universalJar
artifact installerJar
//TODO: installer-win
artifact makeMdk
artifact userdevJar
artifact sourcesJar
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
}
task setup() {
dependsOn ':clean:extractMapped'
dependsOn ':forge:extractMapped'
}