forked from mekanism/Mekanism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
873 lines (797 loc) · 38.4 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
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import mekanism.MergeJars
buildscript {
repositories {
maven {
name 'thiakil'
url "https://maven.thiakil.com"
}
maven {
name "forge"
url "https://maven.minecraftforge.net/"
}
maven {
name 'parchment'
url 'https://maven.parchmentmc.org'
}
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath 'org.parchmentmc:librarian:1.+'
}
}
plugins {
id 'org.ajoberstar.grgit' version '4.1.1'
id "com.matthewprenger.cursegradle" version '1.4.0'
id 'java'
id 'eclipse'
id 'idea'
id 'maven-publish'
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.parchmentmc.librarian.forgegradle'
wrapper {
//Define wrapper values here so as to not have to always do so when updating gradlew.properties
gradleVersion = '7.3.1'
distributionType = Wrapper.DistributionType.ALL
}
defaultTasks 'build'
idea {
module {
// For some reason this is necessary for IDEA 2014 workspaces to recognize assets
inheritOutputDirs = true
//Exclude directories from being managed
for (String excludeDirName in ["run", "out", "logs", "gradle"]) {
File excludeDir = new File(projectDir, excludeDirName)
excludeDirs.add(excludeDir)
}
}
}
sourceSets {
api {
//The API has no resources
resources.srcDirs = []
}
main {
resources {
include '**/**'
// copy everything else, but blender and bbmodel files.
exclude '**/*.blend'
exclude '**/*.bbmodel'
//Add the generated main module resources
srcDirs += 'src/datagen/generated/mekanism'
//But exclude the cache of the generated data from what gets built
exclude '.cache'
}
compileClasspath += api.output
runtimeClasspath += api.output
}
additions { setupSourceSet(additions, 'additions') }
generators { setupSourceSet(generators, 'generators') }
defense { setupSourceSet(defense, 'defense') }
tools { setupSourceSet(tools, 'tools') }
test {
//The test module has no resources
resources.srcDirs = []
compileClasspath += api.output + main.output + additions.output + generators.output + defense.output + tools.output
runtimeClasspath += api.output + main.output + additions.output + generators.output + defense.output + tools.output
}
//Data gen modules for the different modules
datagenmain { setupDataGenSourceSet(datagenmain, null, 'main') }
datagenadditions { setupDataGenSourceSet(datagenadditions, additions, 'additions') }
datagengenerators { setupDataGenSourceSet(datagengenerators, generators, 'generators') }
datagendefense { setupDataGenSourceSet(datagendefense, defense, 'defense') }
datagentools { setupDataGenSourceSet(datagentools, tools, 'tools') }
}
//This method sets up an additional sourceSet in src/$name and adds a reference to the corresponding
// data gen's resource directory excluding the cache. It also adds the api and main mekanism module
// to the dependencies of the source set we are setting up
def setupSourceSet(SourceSet sourceSet, String name) {
sourceSet.resources {
//Add the generated module resources
srcDirs += 'src/datagen/generated/mekanism' + name
//But exclude the cache of the generated data from what gets built
exclude '.cache'
}
sourceSet.compileClasspath += sourceSets.api.output
sourceSet.compileClasspath += sourceSets.main.output
}
//This method sets up a source set in datagen/$name and adds the api, main mekanism module and an optional
// base module to the dependencies of the data generators source set that we are setting up
def setupDataGenSourceSet(SourceSet datagenSourceSet, SourceSet baseSourceSet, String name) {
datagenSourceSet.java.srcDirs = ['src/datagen/' + name + '/java']
datagenSourceSet.compileClasspath += project.sourceSets.api.output
datagenSourceSet.compileClasspath += project.sourceSets.main.output
if (baseSourceSet == null) {
//Base source set has resources that we put files that our annotation processor generates for consumption by our datagen
datagenSourceSet.resources.srcDirs = ['src/datagen/' + name + '/resources']
} else {
//Data gen sourceSets outside of the main one have no resources
datagenSourceSet.resources.srcDirs = []
//Only case it is null is when we are doing datagenmain so other cases also add access to the stuff
// in datagenmain so we can add helper classes
datagenSourceSet.compileClasspath += project.sourceSets.datagenmain.output
datagenSourceSet.compileClasspath += baseSourceSet.output
}
}
configurations {
//Make sure all our sub source set stuff extends the proper base methods so that
// they can see all the dependencies we have in dependencies including forge
extendConfigurations(implementation, apiImplementation, testImplementation, datagenmainImplementation)
extendConfigurations(compileOnly, apiCompileOnly, testCompileOnly, datagenmainCompileOnly)
extendConfigurations(runtimeOnly, apiRuntimeOnly, datagenmainRuntimeOnly)
//Extend configurations for alternate modules. First by making the implementation, compileOnly, runtimeOnly equivalents
// for those modules extend the main ones, and then by making the corresponding ones for datagen for the module extend those.
// This way if we add a dependency/integration in a submodule instead of the main module of Mekanism, the datagen of the corresponding
// module will be able to properly access the dependency
for (def name : ["additions", "defense", "generators", "tools"]) {
maybeCreate("datagen" + name + "Implementation").extendsFrom(maybeCreate(name + "Implementation").extendsFrom(implementation))
maybeCreate("datagen" + name + "CompileOnly").extendsFrom(maybeCreate(name + "CompileOnly").extendsFrom(compileOnly))
maybeCreate("datagen" + name + "RuntimeOnly").extendsFrom(maybeCreate(name + "RuntimeOnly").extendsFrom(runtimeOnly))
}
}
static void extendConfigurations(Configuration base, Configuration... configurations) {
for (def configuration : configurations) {
configuration.extendsFrom(base)
}
}
ext {
versionProperties = ["version" : mod_version, "mc_version": minecraft_version_range, "forge_version": forge_version_range,
"loader_version": loader_version_range, "crafttweaker_version": crafttweaker_version_range, "jei_version": jei_version_range,
"jeitweaker_version": jeitweaker_version_range]
jsonPatterns = ["**/*.json", "**/*.mcmeta"]
}
def mainReplaceResources = createReplaceResourcesTask("main", sourceSets.main)
def additionsReplaceResources = createReplaceResourcesTask("additions", sourceSets.additions)
def generatorsReplaceResources = createReplaceResourcesTask("generators", sourceSets.generators)
def defenseReplaceResources = createReplaceResourcesTask("defense", sourceSets.defense)
def toolsReplaceResources = createReplaceResourcesTask("tools", sourceSets.tools)
def createReplaceResourcesTask(String output, SourceSet sourceSet) {
return tasks.register("${output}ReplaceResources", Copy) {
it.outputs.upToDateWhen { false }
def modsToml = copySpec {
from(sourceSet.resources) {
include "META-INF/mods.toml"
expand versionProperties
}
}
//Copy it into the build dir
it.with modsToml
it.into "$buildDir/resources/${output}/"
//If IntelliJ's output dir exists, copy it there as well
if (new File("$rootDir/out/production/Mekanism.${output}/").exists()) {
//Note: This copies it into the correct place, but it still doesn't have the IntelliJ
// run work by default because of incorrect MOD_CLASSES getting generated.
// probably related to us setting inheritOutputDirs
copy {
with modsToml
into "$rootDir/out/production/Mekanism.${output}/"
}
}
//If Eclipse's output dir exists, copy it there as well
if (new File("$rootDir/bin/${output}/").exists()) {
copy {
with modsToml
into "$rootDir/bin/${output}/"
}
}
}
}
group = "mekanism"
version = "${minecraft_version}-${mod_version}." + (System.env.BUILD_NUMBER ?: "homebaked")
archivesBaseName = "Mekanism"
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
minecraft {
mappings channel: "${mappings_channel}", version: "${mappings_version}"
accessTransformers.from(file('src/main/resources/META-INF/accesstransformer.cfg'),
file('src/additions/resources/META-INF/accesstransformer.cfg'),
file('src/tools/resources/META-INF/accesstransformer.cfg'))
runs {
client {
workingDirectory file("run")
//This fixes Mixin application problems from other mods because their refMaps are SRG-based, but we're in a MCP env
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
//The below if statements are to add args to your gradle.properties file in user home
// (DO NOT add them directly to the gradle.properties file for this project)
// Setting the below properties allows use of your normal Minecraft account in the
// dev environment including having your skin load. Each property also has a comment
// explaining what information to set the value to/format it expects
// One thing to note is because of the caching that goes on, after changing these
// variables, you need to refresh the project and rerun genIntellijRuns/genEclipseRuns
if (project.hasProperty('mc_uuid')) {
//Your uuid without any dashes in the middle
args '--uuid', project.getProperty('mc_uuid')
}
if (project.hasProperty('mc_username')) {
//Your username/display name, this is the name that shows up in chat
// Note: This is not your email, even if you have a Mojang account
args '--username', project.getProperty('mc_username')
}
if (project.hasProperty('mc_accessToken')) {
//Your access token, you can find it in your '.minecraft/launcher_accounts.json' file
args '--accessToken', project.getProperty('mc_accessToken')
}
if (project.hasProperty('forge_force_ansi')) {
//Force ansi if declared as a gradle variable, as the auto detection doesn't detect IntelliJ properly
// or eclipse's plugin that adds support for ansi escape in console
jvmArg('-Dterminal.ansi=' + project.getProperty('forge_force_ansi'))
}
mods {
mekanism.sources((SourceSet[]) [sourceSets.main, sourceSets.api])
mekanismadditions.source((SourceSet) sourceSets.additions)
mekanismdefense.source((SourceSet) sourceSets.defense)
mekanismgenerators.source((SourceSet) sourceSets.generators)
mekanismtools.source((SourceSet) sourceSets.tools)
}
}
server {
workingDirectory file("run")
//This fixes Mixin application problems from other mods because their refMaps are SRG-based, but we're in a MCP env
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
if (project.hasProperty('forge_force_ansi')) {
//Force ansi if declared as a gradle variable, as the auto detection doesn't detect IntelliJ properly
// or eclipse's plugin that adds support for ansi escape in console
jvmArg('-Dterminal.ansi=' + project.getProperty('forge_force_ansi'))
}
mods {
mekanism.sources((SourceSet[]) [sourceSets.main, sourceSets.api])
mekanismadditions.source((SourceSet) sourceSets.additions)
mekanismdefense.source((SourceSet) sourceSets.defense)
mekanismgenerators.source((SourceSet) sourceSets.generators)
mekanismtools.source((SourceSet) sourceSets.tools)
}
}
data {
workingDirectory file("run")
environment 'target', 'fmluserdevdata'
//This fixes Mixin application problems from other mods because their refMaps are SRG-based, but we're in a MCP env
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
if (project.hasProperty('forge_force_ansi')) {
//Force ansi if declared as a gradle variable, as the auto detection doesn't detect IntelliJ properly
// or eclipse's plugin that adds support for ansi escape in console
jvmArg('-Dterminal.ansi=' + project.getProperty('forge_force_ansi'))
}
args '--all', '--output', file('src/datagen/generated/'),
'--mod', 'mekanism',
'--existing', file('src/main/resources/'),
'--mod', 'mekanismadditions',
'--existing', file('src/additions/resources/'),
'--mod', 'mekanismdefense',
'--existing', file('src/defense/resources/'),
'--mod', 'mekanismgenerators',
'--existing', file('src/generators/resources/'),
'--mod', 'mekanismtools',
'--existing', file('src/tools/resources/')
mods {
mekanism.sources((SourceSet[]) [sourceSets.main, sourceSets.api, sourceSets.datagenmain])
mekanismadditions.sources((SourceSet[]) [sourceSets.additions, sourceSets.datagenadditions])
mekanismdefense.sources((SourceSet[]) [sourceSets.defense, sourceSets.datagendefense])
mekanismgenerators.sources((SourceSet[]) [sourceSets.generators, sourceSets.datagengenerators])
mekanismtools.sources((SourceSet[]) [sourceSets.tools, sourceSets.datagentools])
}
}
}
}
repositories {
maven {
name 'thiakil'
url 'https://maven.thiakil.com'
content {
includeGroup 'de.oceanlabs.mcp'
includeGroup 'net.minecraft'//custom mappings
}
}
maven {
name 'prog'
url 'https://dvs1.progwml6.com/files/maven'
content {
includeGroup 'mezz.jei'
}
}
maven {
name 'CraftTweaker'
url "https://maven.blamejared.com"
content {
includeGroup 'com.blamejared.crafttweaker'
includeGroup 'com.blamejared.jeitweaker'
}
}
maven {
name 'curios'
url "https://maven.theillusivec4.top/"
content {
includeGroup 'top.theillusivec4.curios'
}
}
maven {
name 'tterrag'
url 'https://maven.tterrag.com/'
content {
includeGroupByRegex 'com\\.enderio.*'
includeGroupByRegex 'com\\.enderzoo.*'
includeGroupByRegex 'com\\.tterrag.*'
includeGroupByRegex 'tterrag.*'
includeGroup 'mcjty.theoneprobe'
includeGroup 'team.chisel.ctm'
}
}
maven {
name 'ComputerCraft'
url "https://squiddev.cc/maven/"
content {
includeGroup 'org.squiddev'
}
}
maven {
name 'CurseMaven'
url 'https://www.cursemaven.com'
content {
includeGroup 'curse.maven'
}
}
maven {
name 'Modmaven'
url 'https://modmaven.dev/'
content {
includeGroup 'appeng'
}
}
whenObjectAdded {//ForgeGradle adds these in an afterEvaluate, so we need to catch them as they're added and exclude mod artifacts/groups
if (it instanceof MavenArtifactRepository) {
def url = it.url.toString()
if (url == 'https://maven.minecraftforge.net/' || url == 'https://libraries.minecraft.net/' || url == 'https://repo.maven.apache.org/maven2/') {
try {
it.content {
excludeGroup 'curse.maven'
excludeGroup 'mezz.jei'
excludeGroupByRegex 'com\\.enderio.*'
excludeGroupByRegex 'com\\.enderzoo.*'
excludeGroupByRegex 'com\\.tterrag.*'
excludeGroupByRegex 'tterrag.*'
excludeGroup 'mcjty.theoneprobe'
excludeGroup 'team.chisel.ctm'
excludeGroup 'appeng'
excludeGroup 'org.squiddev'
excludeGroup 'com.blamejared.crafttweaker'
excludeGroup 'com.blamejared.jeitweaker'
excludeGroup 'top.theillusivec4.curios'
}
println("Adding exclusions to ${it.url}")
} catch (Exception ignored) {
//oh well
}
}
}
}
}
test {
useJUnitPlatform()
}
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
annotationProcessor project(":annotation-processor")
testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_version}"
//We use https://github.com/quicktheories/QuickTheories to allow for implementing property based testing
testImplementation "org.quicktheories:quicktheories:${quicktheories_version}"
compileOnly "org.jetbrains:annotations:${jb_annotations}"
compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}:${jei_version}:api")
runtimeOnly fg.deobf("mezz.jei:jei-${minecraft_version}:${jei_version}")
runtimeOnly fg.deobf("team.chisel.ctm:CTM:MC1.16.1-${ctm_version}")
compileOnly fg.deobf("mcjty.theoneprobe:TheOneProbe-1.16:${top_version}:api")
runtimeOnly fg.deobf("mcjty.theoneprobe:TheOneProbe-1.16:${top_version}")
compileOnly fg.deobf("curse.maven:jade-api-324717:${jade_api_id}")
runtimeOnly fg.deobf("curse.maven:jade-324717:${jade_id}")
implementation fg.deobf("com.blamejared.crafttweaker:CraftTweaker-${minecraft_version}:${crafttweaker_version}")
implementation fg.deobf("com.blamejared.jeitweaker:JEITweaker-${minecraft_version}:${jeitweaker_version}")
//Mods we have dependencies on but don't bother loading into the dev environment
compileOnly fg.deobf("curse.maven:projecte-api-226410:${projecte_api_id}")
compileOnly fg.deobf("curse.maven:flux-networks-248020:${flux_networks_id}")
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api")
compileOnly fg.deobf("org.squiddev:cc-tweaked-${minecraft_version}:${computer_craft_version}")
//We require cc tweaked so that our CCArgumentWrapper tests can load, so expose it to the test runtime
testRuntimeOnly fg.deobf("org.squiddev:cc-tweaked-${minecraft_version}:${computer_craft_version}")
//Dependencies for data generators for mod compat reference
datagenmainImplementation fg.deobf("appeng:appliedenergistics2:${ae2_version}") {
transitive = false
}
datagenmainCompileOnly fg.deobf("curse.maven:biomes-o-plenty-api-220318:${biomesoplenty_api_id}")
datagenmainRuntimeOnly fg.deobf("curse.maven:biomes-o-plenty-220318:${biomesoplenty_id}")
datagenmainImplementation fg.deobf("curse.maven:biomes-youll-go-247560:${byg_id}")
datagenmainImplementation fg.deobf("curse.maven:i-like-wood-324164:${ilikewood_id}")
datagenmainImplementation fg.deobf("curse.maven:i-like-wood-biomes-o-plenty-437203:${ilikewood_bop_id}")
datagenmainImplementation fg.deobf("curse.maven:i-like-wood-oh-the-biomes-youll-go-475110:${ilikewood_byg_id}")
datagenmainRuntimeOnly fg.deobf("curse.maven:projecte-226410:${projecte_id}")
}
if (project.hasProperty('UPDATE_MAPPINGS')) {
//If the project has the update mappings property, configure it to be able to target all our extra sourceSets as well
// so that whenever we need to update mappings it is quick and easy to do so.
// Note: This needs to be below the dependencies and minecraft blocks so that it can properly read the mappings value
// and also read and find the minecraft dep
def extraSourceSets = [sourceSets.api, sourceSets.additions, sourceSets.generators, sourceSets.defense, sourceSets.tools, sourceSets.test,
sourceSets.datagenmain, sourceSets.datagenadditions, sourceSets.datagengenerators, sourceSets.datagendefense, sourceSets.datagentools]
Set<File> allExtraDirs = new HashSet<>()
for (def sourceSet : extraSourceSets) {
allExtraDirs.addAll(sourceSet.java.srcDirs)
}
extractRangeMap {
sources.from(allExtraDirs)
}
applyRangeMap {
sources.from(allExtraDirs)
}
allExtraDirs.each { extractMappedNew.addTarget it }
}
//Set the various variables/settings for the different process resources tasks
processResources { setupProcessResources(processResources, mainReplaceResources) }
processAdditionsResources { setupProcessResources(processAdditionsResources, additionsReplaceResources) }
processDefenseResources { setupProcessResources(processDefenseResources, defenseReplaceResources) }
processGeneratorsResources { setupProcessResources(processGeneratorsResources, generatorsReplaceResources) }
processToolsResources { setupProcessResources(processToolsResources, toolsReplaceResources) }
processDatagenmainResources { dependsOn(compileJava) }
def setupProcessResources(ProcessResources process, TaskProvider<Task> replaceResources) {
process.duplicatesStrategy(DuplicatesStrategy.FAIL)
process.exclude('META-INF/mods.toml')
process.from("${projectDir}") { include 'logo.png' }
process.configure { finalizedBy(replaceResources) }
process.doLast {
fileTree(dir: process.getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file)))
}
}
}
//Make the various classes tasks depend on the corresponding replaceResources tasks in addition to the default processResources tasks they depend on
classes.configure { dependsOn(mainReplaceResources) }
additionsClasses.configure { dependsOn(additionsReplaceResources) }
defenseClasses.configure { dependsOn(defenseReplaceResources) }
generatorsClasses.configure { dependsOn(generatorsReplaceResources) }
toolsClasses.configure { dependsOn(toolsReplaceResources) }
def getManifestAttributes(String title) {
return [
"Specification-Title" : title,
"Specification-Vendor" : "Mekanism",
"Specification-Version" : "${project.mod_version}",
"Implementation-Title" : title,
"Implementation-Version" : "${project.mod_version}",
"Implementation-Vendor" : "Mekanism",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
]
}
jar {
duplicatesStrategy(DuplicatesStrategy.FAIL)
from([sourceSets.api.output, sourceSets.main.output])
manifest.attributes(getManifestAttributes("Mekanism"))
afterEvaluate { finalizedBy reobfJar }
}
task sourcesJar(type: Jar, dependsOn: [classes, apiClasses, additionsClasses, defenseClasses, generatorsClasses, toolsClasses]) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set("sources")
from(sourceSets.api.allJava, sourceSets.main.allJava, sourceSets.additions.allJava, sourceSets.defense.allJava, sourceSets.generators.allJava, sourceSets.tools.allJava)
manifest.attributes(getManifestAttributes("Mekanism"))
}
task apiJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set("api")
from sourceSets.api.output
manifest.attributes(getManifestAttributes("Mekanism"))
afterEvaluate { finalizedBy reobfApiJar }
}
task additionsJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveFileName.set("MekanismAdditions-${project.version}.jar")
archiveClassifier.set("additions")
from sourceSets.additions.output
manifest.attributes(getManifestAttributes("MekanismAdditions"))
afterEvaluate { finalizedBy reobfAdditionsJar }
}
task defenseJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveFileName.set("MekanismDefense-${project.version}.jar")
archiveClassifier.set("defense")
from sourceSets.defense.output
manifest.attributes(getManifestAttributes("MekanismDefense"))
afterEvaluate { finalizedBy reobfDefenseJar }
}
task generatorsJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveFileName.set("MekanismGenerators-${project.version}.jar")
archiveClassifier.set("generators")
from sourceSets.generators.output
manifest.attributes(getManifestAttributes("MekanismGenerators"))
afterEvaluate { finalizedBy reobfGeneratorsJar }
}
task toolsJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveFileName.set("MekanismTools-${project.version}.jar")
archiveClassifier.set("tools")
from sourceSets.tools.output
manifest.attributes(getManifestAttributes("MekanismTools"))
afterEvaluate { finalizedBy reobfToolsJar }
}
task allJar(type: Jar, dependsOn: [classes, apiClasses, additionsClasses, defenseClasses, generatorsClasses, toolsClasses]) {
mustRunAfter(clean)
afterEvaluate { finalizedBy reobfAllJar }
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set("all")
manifest.attributes(getManifestAttributes("MekanismAll"))
//Start by generating the merged data
MergeJars.merge(project, sourceSets.main, sourceSets.additions, sourceSets.defense, sourceSets.generators, sourceSets.tools)
//Then copy all the files except for ones we are going to include from the merged
from(sourceSets.api.output)
List<String> baseExcludeData = MergeJars.getGeneralPathsToExclude(project)
Closure excludeFromMain = MergeJars.createExcludeClosure(baseExcludeData)
from(sourceSets.main.output, excludeFromMain)
Closure excludeFromAll = MergeJars.createExcludeClosure(baseExcludeData, 'logo.png', 'pack.mcmeta')
from(sourceSets.additions.output, excludeFromAll)
from(sourceSets.defense.output, excludeFromAll)
from(sourceSets.generators.output, excludeFromAll)
from(sourceSets.tools.output, excludeFromAll)
//And finally copy over the generated files
MergeJars.getGeneratedClosures(versionProperties).each { closure -> from("$buildDir/generated", closure) }
}
tasks.withType(JavaCompile).configureEach({
it.options.encoding = 'UTF-8'
})
compileJava {
options.annotationProcessorPath = configurations.annotationProcessor
options.annotationProcessorGeneratedSourcesDirectory = layout.buildDirectory.file("src/datagen/main/resources/").map(r -> r.asFile)
options.compilerArgs = [
"-processor", "mekanism.CraftTweakerParamNameMapper"
]
}
artifacts {
archives apiJar
archives jar
archives additionsJar
archives generatorsJar
archives defenseJar
archives toolsJar
archives allJar
archives sourcesJar
}
reobf {
apiJar { classpath.from(sourceSets.api.compileClasspath) }
jar { classpath.from(sourceSets.main.compileClasspath) }
additionsJar { classpath.from(sourceSets.additions.compileClasspath) }
generatorsJar { classpath.from(sourceSets.generators.compileClasspath) }
defenseJar { classpath.from(sourceSets.defense.compileClasspath) }
toolsJar { classpath.from(sourceSets.tools.compileClasspath) }
allJar {}
}
//Minimize/optimize all png files, requires optipng on the PATH
// Credits: BrainStone
void minimizePNGFile(File file) {
long size = file.length()
exec {
executable "optipng"
args "-q", "-o7", "-zm1-9", "-strip", "all", file
}
long newSize = file.length()
if (newSize < size) {
System.out.format("Reduced File size of %s from %d bytes to %d bytes (reduced by %.2f%%)\n",
file, size, newSize, ((double) (size - newSize)) / ((double) size) * 100.0)
}
}
task optimizePng {
def pngPatterns = ["**/*.png"]
doLast {
//Ensure the logo is minimized (we add this file to each jar)
minimizePNGFile(file("${projectDir}/logo.png"))
//Minimize any PNGs in the source sets
def sourceSets = [sourceSets.main, sourceSets.additions, sourceSets.generators, sourceSets.defense, sourceSets.tools]
for (def sourceSet : sourceSets) {
for (dir in sourceSet.resources.srcDirs) {
fileTree(dir: dir, includes: pngPatterns).each { minimizePNGFile(it) }
}
}
}
}
tasks.withType(GenerateModuleMetadata) {
//Disable Gradle 7 module metadata generation as it does not play nicely with FG
enabled = false
}
//properties to put in $HOME/.gradle/gradle.properties
def MAVEN_PASSWORD_PROPERTY_NAME = 'mekanismMavenPassword'
publishing {
publications { PublicationContainer publicationContainer ->
publicationContainer.register("maven", MavenPublication) { MavenPublication publication ->
publication.from((SoftwareComponent) components.java)
publication.groupId = project.group
publication.version = project.version
publication.artifactId = System.getenv("MAVEN_ARTIFACT") ?: project.archivesBaseName
publication.artifacts = [apiJar, jar, generatorsJar, additionsJar, toolsJar, allJar, sourcesJar]
publication.pom {
name.set("Mekanism")
packaging = 'jar'
description.set('Mekanism is a Minecraft add-on featuring high-tech machinery that can be used to create powerful tools, armor, and weapons.')
url.set('https://aidancbrady.com/mekanism/')
scm {
url.set('https://github.com/mekanism/Mekanism.git')
}
issueManagement {
system.set('github')
url.set('https://github.com/mekanism/Mekanism/issues')
}
licenses {
license {
name.set('MIT')
distribution.set('repo')
}
}
withXml {
NodeList dependencies = asNode().dependencies
NodeList allDeps = dependencies.'*'
// Remove forge deps
allDeps.<Node> findAll() { Node el ->
el.artifactId.text() == 'forge' && el.groupId.text() == 'net.minecraftforge'
}.forEach() { Node el ->
el.parent().remove(el)
}
//remove ForgeGradle's mapped suffix from versions & set as optional so anyone else doesn't inherit them
allDeps.<Node> findAll() { Node el ->
el.version.text().contains('_mapped_')
}.each { Node el ->
el.version.each { Node version ->
def versionText = version.text()
version.setValue(versionText.substring(0, versionText.indexOf('_mapped_')))
}
el.appendNode('optional', true)
}
}
}
}
}
repositories {
maven {
url = 'https://modmaven.dev/artifactory/local-releases/'
if (project.findProperty(MAVEN_PASSWORD_PROPERTY_NAME) != null) {
credentials {
username = "mekanism"
password = project.findProperty(MAVEN_PASSWORD_PROPERTY_NAME)
}
}
}
}
}
tasks.curseforge.dependsOn jar, additionsJar, generatorsJar, /*defenseJar,*/ toolsJar, apiJar
if (System.getenv("CURSEFORGE_KEY") != null || project.hasProperty('curseforgeKey')) {
println "Enabling Curseforge config"
curseforge {
apiKey = System.getenv("CURSEFORGE_KEY") ?: project.findProperty("curseforgeKey")
def resolvedChangelog = null
//closure to generate the changelog once, and only when needed by CurseGradle
def changeLogResolver = { ->
if (resolvedChangelog != null) {
return resolvedChangelog
}
def generatedChangelog = "Unable to generate changelog :("
def currentCommit = System.getenv("GIT_COMMIT")
def prevCommit = System.getenv("GIT_PREVIOUS_SUCCESSFUL_COMMIT") ?: System.getenv("GIT_PREVIOUS_COMMIT")
if (currentCommit != null && prevCommit != null) {
generatedChangelog = ""
grgit.log {
range(prevCommit, currentCommit)
}.reverse().each { commit ->
//Use full message rather than short message to get any new lines, and trim it so that any trailing new lines
// get removed so that we don't end up with extra spaces
String message = commit.fullMessage.trim()
if (!message.startsWith("Merge branch") && !message.startsWith("Merge pull request")) {
//Ignore Merges and PR Merges
message = message.replaceAll("#(\\d+)", { match ->//turn issues/prs into links (github currently supports prs being linked as issues)
return "<a href=\"https://github.com/mekanism/Mekanism/issues/${match[1]}\">${match[0]}</a>"
}).replaceAll("\\n", "<br> ")//convert new lines that are part of a commit message into actual new lines and a tab
if (generatedChangelog != "") {
//If this isn't the first commit prepend an extra newline
generatedChangelog += "<br>"
}
generatedChangelog += "<a href=\"https://github.com/mekanism/Mekanism/commit/${commit.id}\">${commit.getAbbreviatedId()}</a> - ${message}"
}
}
println "Changelog generated"
}
def releaseNotesFile = project.file("docs/release_${mod_version}.html")
if (releaseNotesFile.exists()) {
//Add any version specific changelog stuff
def releaseNotes = releaseNotesFile.getText()
generatedChangelog = "$releaseNotes<br> $generatedChangelog"
}
if (curse_release_type == "alpha") {
//Add a warning at the top about what an alpha build means
generatedChangelog = "Warning: Mekanism is currently in alpha, and is not recommended for widespread use in modpacks. There are likely to be game breaking bugs, " +
"and updating from one alpha to the next may cause various mekanism blocks to disappear/void their contents. While we will try to not have this happen/keep " +
"it to a minimum make sure to make backups. You can read more about the alpha state of this project <a href=\"https://github.com/mekanism/Mekanism#alpha-status\">here</a>." +
"<br> $generatedChangelog"
}
resolvedChangelog = generatedChangelog
return generatedChangelog
}
//Main
project {
id = '268560'
changelogType = "html"
changelog = changeLogResolver
// A file can also be set using: changelog = file('changelog.txt')
releaseType = "${curse_release_type}"
mainArtifact(jar) {
relations {
optionalDependency "applied-energistics-2"
optionalDependency "biomes-o-plenty"
optionalDependency "cc-tweaked"
optionalDependency "crafttweaker"
optionalDependency "ctm"
optionalDependency "curios"
optionalDependency "flux-networks"
optionalDependency "hwyla"
optionalDependency "i-like-wood"
optionalDependency "i-like-wood-biomes-o-plenty-plugin"
optionalDependency "i-like-wood-oh-the-biomes-youll-go-plugin"
optionalDependency "jade"
optionalDependency "jei"
optionalDependency "jeitweaker"
optionalDependency "oh-the-biomes-youll-go"
optionalDependency "perviaminvenire"
optionalDependency "projecte"
optionalDependency "the-one-probe"
}
}
addArtifact apiJar
addGameVersion "${minecraft_version}"
}
//Additions
project {
id = '345425'
changelogType = "html"
changelog = changeLogResolver
releaseType = "${curse_release_type}"
mainArtifact(additionsJar) {
relations {
requiredDependency "mekanism"
}
}
addGameVersion "${minecraft_version}"
}
//Defense
/*project {
id = '376939'
changelogType = "html"
changelog = changeLogResolver
releaseType = "${curse_release_type}"
mainArtifact(defenseJar) {
relations {
requiredDependency "mekanism"
}
}
addGameVersion "${minecraft_version}"
}*/
//Generators
project {
id = '268566'
changelogType = "html"
changelog = changeLogResolver
releaseType = "${curse_release_type}"
mainArtifact(generatorsJar) {
relations {
requiredDependency "mekanism"
}
}
addGameVersion "${minecraft_version}"
}
//Tools
project {
id = '268567'
changelogType = "html"
changelog = changeLogResolver
releaseType = "${curse_release_type}"
mainArtifact(toolsJar) {
relations {
requiredDependency "mekanism"
}
}
addGameVersion "${minecraft_version}"
}
}
}