forked from mekanism/Mekanism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
853 lines (783 loc) · 32.7 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
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
buildscript {
repositories {
jcenter()
maven {
name "forge"
url "https://files.minecraftforge.net/maven"
}
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
plugins {
id 'org.ajoberstar.grgit' version '4.0.2'
id "com.matthewprenger.cursegradle" version '1.4.0'
id 'java'
id 'idea'
id 'maven'
id 'maven-publish'
}
defaultTasks 'fullBuild'
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)
}
}
}
apply plugin: 'net.minecraftforge.gradle'
sourceSets {
api {
java {
srcDir 'src/api/java'
}
}
main {
java {
srcDir 'src/main/java'
}
resources {
include '**/**'
// copy everything else, but blender files.
exclude '**/*.blend'
//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 += sourceSets.api.output
runtimeClasspath += sourceSets.api.output
}
additions { setupSourceSet(sourceSets.additions, 'additions') }
generators { setupSourceSet(sourceSets.generators, 'generators') }
defense { setupSourceSet(sourceSets.defense, 'defense') }
tools { setupSourceSet(sourceSets.tools, 'tools') }
test {
compileClasspath += sourceSets.api.output + sourceSets.main.output + sourceSets.additions.output + sourceSets.generators.output + sourceSets.defense.output + sourceSets.tools.output
runtimeClasspath += sourceSets.api.output + sourceSets.main.output + sourceSets.additions.output + sourceSets.generators.output + sourceSets.defense.output + sourceSets.tools.output
}
//Data gen modules for the different modules
datagenmain { setupDataGenSourceSet(sourceSets.datagenmain, null, 'main') }
datagenadditions { setupDataGenSourceSet(sourceSets.datagenadditions, sourceSets.additions, 'additions') }
datagengenerators { setupDataGenSourceSet(sourceSets.datagengenerators, sourceSets.generators, 'generators') }
datagendefense { setupDataGenSourceSet(sourceSets.datagendefense, sourceSets.defense, 'defense') }
datagentools { setupDataGenSourceSet(sourceSets.datagentools, sourceSets.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.java {
srcDir 'src/' + name + '/java'
}
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.resources.srcDirs = ['src/datagen/' + name + '/resources']
datagenSourceSet.compileClasspath += project.sourceSets.api.output
datagenSourceSet.compileClasspath += project.sourceSets.main.output
if (baseSourceSet != null) {
//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
def compileExtenders = [apiCompile, additionsCompile, generatorsCompile, defenseCompile, toolsCompile, testCompile,
datagenmainCompile, datagenadditionsCompile, datagengeneratorsCompile, datagendefenseCompile, datagentoolsCompile]
def implementationExtenders = [apiImplementation, additionsImplementation, generatorsImplementation, defenseImplementation, toolsImplementation, testImplementation,
datagenmainImplementation, datagenadditionsImplementation, datagengeneratorsImplementation, datagendefenseImplementation, datagentoolsImplementation]
def compileOnlyExtenders = [apiCompileOnly, additionsCompileOnly, generatorsCompileOnly, defenseCompileOnly, toolsCompileOnly, testCompileOnly,
datagenmainCompileOnly, datagenadditionsCompileOnly, datagengeneratorsCompileOnly, datagendefenseCompileOnly, datagentoolsCompileOnly]
def runtimeOnlyExtenders = [apiRuntimeOnly, additionsRuntimeOnly, generatorsRuntimeOnly, defenseRuntimeOnly, toolsRuntimeOnly,
datagenmainRuntimeOnly, datagenadditionsRuntimeOnly, datagengeneratorsRuntimeOnly, datagendefenseRuntimeOnly, datagentoolsRuntimeOnly]
for (def compileExtender : compileExtenders) {
compileExtender.extendsFrom(compile)
}
for (def implementationExtender : implementationExtenders) {
implementationExtender.extendsFrom(implementation)
}
for (def compileOnlyExtender : compileOnlyExtenders) {
compileOnlyExtender.extendsFrom(compileOnly)
}
for (def runtimeOnlyExtender : runtimeOnlyExtenders) {
runtimeOnlyExtender.extendsFrom(runtimeOnly)
}
}
def version_properties = ["version" : mod_version, "mc_version": minecraft_version, "forge_version": min_forge_version,
"loader_version": loader_version]
def jsonPatterns = ["**/*.json", "**/*.mcmeta"]
ext {
replaceResourcesInfo = [
"main" : sourceSets.main,
"additions" : sourceSets.additions,
"generators": sourceSets.generators,
"defense" : sourceSets.defense,
"tools" : sourceSets.tools,
]
}
replaceResourcesInfo.each { output, sourceSet ->
return tasks.create("${output}ReplaceResources", Copy) {
outputs.upToDateWhen { false }
from(sourceSet.resources) {
include "META-INF/mods.toml"
expand version_properties
}
into "$buildDir/resources/${output}/"
}
}
group = "mekanism"
version = "${minecraft_version}-${mod_version}." + (System.env.BUILD_NUMBER ?: "homebaked")
archivesBaseName = "Mekanism"
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
minecraft {
mappings channel: "snapshot", version: "${mappings_version}"
accessTransformers(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 project.file("run")
//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_profiles.json' file
args '--accessToken', project.getProperty('mc_accessToken')
}
mods {
mekanism {
sources(sourceSets.main, sourceSets.api)
}
mekanismadditions {
source(sourceSets.additions)
}
mekanismgenerators {
source(sourceSets.generators)
}
mekanismdefense {
source(sourceSets.defense)
}
mekanismtools {
source(sourceSets.tools)
}
}
}
server {
workingDirectory project.file("run")
mods {
mekanism {
sources(sourceSets.main, sourceSets.api)
}
mekanismadditions {
source(sourceSets.additions)
}
mekanismgenerators {
source(sourceSets.generators)
}
mekanismdefense {
source(sourceSets.defense)
}
mekanismtools {
source(sourceSets.tools)
}
}
}
data {
workingDirectory project.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.disableRefMap", "true"
args '--all', '--output', file('src/datagen/generated/'),
'--mod', 'mekanism',
'--existing', sourceSets.main.resources.srcDirs[0],
'--mod', 'mekanismadditions',
'--existing', sourceSets.additions.resources.srcDirs[0],
'--mod', 'mekanismgenerators',
'--existing', sourceSets.generators.resources.srcDirs[0],
'--mod', 'mekanismdefense',
'--existing', sourceSets.defense.resources.srcDirs[0],
'--mod', 'mekanismtools',
'--existing', sourceSets.tools.resources.srcDirs[0]
mods {
mekanism {
sources(sourceSets.main, sourceSets.api, sourceSets.datagenmain)
}
mekanismadditions {
sources(sourceSets.additions, sourceSets.datagenadditions)
}
mekanismgenerators {
sources(sourceSets.generators, sourceSets.datagengenerators)
}
mekanismdefense {
sources(sourceSets.defense, sourceSets.datagendefense)
}
mekanismtools {
sources(sourceSets.tools, sourceSets.datagentools)
}
}
}
}
}
repositories {
maven {
name 'ForgeFS'
url 'https://files.minecraftforge.net/maven'
content {
includeGroupByRegex 'net\\.minecraftforge.*'
includeGroup 'de.oceanlabs.mcp'
includeGroup 'cpw.mods'
}
}
maven {
name 'prog'
url 'https://dvs1.progwml6.com/files/maven'
content {
includeGroup 'mezz.jei'
}
}
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 'CurseMaven'
url 'https://www.cursemaven.com'
content {
includeGroup 'curse.maven'
}
}
maven {
name 'Modmaven'
url 'https://modmaven.k-4u.nl'
content {
includeGroup 'appeng'
}
}
maven {
name 'HWYLA'
url "https://maven.tehnut.info"
content {
includeGroup 'mcp.mobius.waila'
}
}
}
test {
useJUnitPlatform()
}
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
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("mcp.mobius.waila:Hwyla:${hwyla_version}:api")
runtimeOnly fg.deobf("mcp.mobius.waila:Hwyla:${hwyla_version}")
//Mods we have dependencies on but don't bother loading into the dev environment
//compileOnly fg.deobf("curse.maven:projecte:${projecte_api_id}")
compileOnly fg.deobf("curse.maven:flux-networks:${flux_networks_id}")
//Dependencies for data generators for mod compat reference
datagenmainImplementation fg.deobf("appeng:appliedenergistics2:${ae2_version}")
datagenmainCompileOnly fg.deobf("curse.maven:biomes-o-plenty-api:${biomesoplenty_api_id}")
datagenmainRuntimeOnly fg.deobf("curse.maven:biomes-o-plenty:${biomesoplenty_id}")
datagenmainImplementation fg.deobf("curse.maven:i-like-wood:${ilikewood_id}")
}
processResources {
//Exclude the mods.toml file as we manually handle that and don't want it to invalidate our cache
exclude 'META-INF/mods.toml'
//Add our logo file
from("${projectDir}") { include 'logo.png' }
finalizedBy mainReplaceResources
//Minify json resources
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file)))
}
}
}
processAdditionsResources {
//Exclude the mods.toml file as we manually handle that and don't want it to invalidate our cache
exclude 'META-INF/mods.toml'
//Add our logo file
from("${projectDir}") { include 'logo.png' }
finalizedBy additionsReplaceResources
//Minify json resources
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file)))
}
}
}
processDefenseResources {
//Exclude the mods.toml file as we manually handle that and don't want it to invalidate our cache
exclude 'META-INF/mods.toml'
//Add our logo file
from("${projectDir}") { include 'logo.png' }
finalizedBy defenseReplaceResources
//Minify json resources
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file)))
}
}
}
processGeneratorsResources {
//Exclude the mods.toml file as we manually handle that and don't want it to invalidate our cache
exclude 'META-INF/mods.toml'
//Add our logo file
from("${projectDir}") { include 'logo.png' }
finalizedBy generatorsReplaceResources
//Minify json resources
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file)))
}
}
}
processToolsResources {
//Exclude the mods.toml file as we manually handle that and don't want it to invalidate our cache
exclude 'META-INF/mods.toml'
//Add our logo file
from("${projectDir}") { include 'logo.png' }
finalizedBy toolsReplaceResources
//Minify json resources
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file)))
}
}
}
def getManifestAttributes(String title) {
//TODO: Eventually we may want to try and improve the information supplied here
// if there are parts of it that are not as they are supposed to be
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 {
from sourceSets.api.output
from sourceSets.main.output
manifest.attributes(getManifestAttributes("Mekanism"))
}
//TODO: Sources Jars?
task apiJar(type: Jar) {
classifier "api"
from sourceSets.api.output
}
task additionsJar(type: Jar) {
//Mark that it shouldn't run before the replace resources gets run
shouldRunAfter(additionsReplaceResources)
archiveName = "MekanismAdditions-${project.version}.jar"
classifier = "additions"
from sourceSets.additions.output
manifest.attributes(getManifestAttributes("MekanismAdditions"))
afterEvaluate {
finalizedBy reobfAdditionsJar
}
}
task defenseJar(type: Jar) {
//Mark that it shouldn't run before the replace resources gets run
shouldRunAfter(defenseReplaceResources)
archiveName = "MekanismDefense-${project.version}.jar"
classifier = "defense"
from sourceSets.defense.output
manifest.attributes(getManifestAttributes("MekanismDefense"))
afterEvaluate {
finalizedBy reobfDefenseJar
}
}
task generatorsJar(type: Jar) {
//Mark that it shouldn't run before the replace resources gets run
shouldRunAfter(generatorsReplaceResources)
archiveName = "MekanismGenerators-${project.version}.jar"
classifier = "generators"
from sourceSets.generators.output
manifest.attributes(getManifestAttributes("MekanismGenerators"))
afterEvaluate {
finalizedBy reobfGeneratorsJar
}
}
task toolsJar(type: Jar) {
//Mark that it shouldn't run before the replace resources gets run
shouldRunAfter(toolsReplaceResources)
archiveName = "MekanismTools-${project.version}.jar"
classifier = "tools"
from sourceSets.tools.output
manifest.attributes(getManifestAttributes("MekanismTools"))
afterEvaluate {
finalizedBy reobfToolsJar
}
}
//TODO: Fix the fact that the all jar does not properly merge overlapping tags (cardboard_blacklist, and piglin_loved)
task allJar(type: Jar) {
//Make sure the other tasks run first
shouldRunAfter(apiJar, jar, additionsJar, defenseJar, generatorsJar, toolsJar,
processResources, processAdditionsResources, processDefenseResources,
processGeneratorsResources, processToolsResources)
afterEvaluate {
finalizedBy reobfAllJar
}
classifier "all"
manifest.attributes(getManifestAttributes("MekanismAll"))
doFirst {
//Generate folders, merge the access transformers and mods.toml files
mkdir("$buildDir/generated/META-INF")
(new File("$buildDir/generated/META-INF/accesstransformer.cfg")).text = mergeATs(sourceSets.main,
sourceSets.additions, sourceSets.defense, sourceSets.generators, sourceSets.tools)
(new File("$buildDir/generated/META-INF/mods.toml")).text = mergeModsTOML(sourceSets.main,
sourceSets.additions, sourceSets.defense, sourceSets.generators, sourceSets.tools)
}
from(sourceSets.api.output)
from(sourceSets.main.output) {
exclude 'META-INF/mods.toml', 'META-INF/accesstransformer.cfg'
}
Closure excluded = {
exclude 'META-INF/mods.toml', 'META-INF/accesstransformer.cfg', 'logo.png', 'pack.mcmeta'
}
from(sourceSets.additions.output, excluded)
from(sourceSets.defense.output, excluded)
from(sourceSets.generators.output, excluded)
from(sourceSets.tools.output, excluded)
//Copy over the generated files
from("$buildDir/generated") {
include 'META-INF/mods.toml'
expand version_properties
}
from("$buildDir/generated") {
include 'META-INF/accesstransformer.cfg'
}
}
static String mergeATs(SourceSet... sourceSets) {
String text = ""
for (SourceSet sourceSet : sourceSets) {
sourceSet.resources.matching {
include 'META-INF/accesstransformer.cfg'
}.each {
File file -> text = text.isEmpty() ? file.getText() : text + "\n" + file.getText()
}
}
return text
}
static String mergeModsTOML(SourceSet... sourceSets) {
String text = ""
for (SourceSet sourceSet : sourceSets) {
sourceSet.resources.matching {
include 'META-INF/mods.toml'
}.each {
File file ->
if (text.isEmpty()) {
//Nothing added yet, take it all
text = file.getText()
} else {
//Otherwise add all but the first four lines (which are duplicated between the files)
String[] lines = file.getText().split("\n")
for (int i = 4; i < lines.length; i++) {
text = text + "\n" + lines[i]
}
}
}
}
return text
}
artifacts {
archives apiJar
archives jar
archives additionsJar
archives generatorsJar
archives defenseJar
archives toolsJar
archives allJar
}
reobf {
apiJar { classpath = sourceSets.api.compileClasspath }
jar { classpath = sourceSets.main.compileClasspath }
additionsJar { classpath = sourceSets.additions.compileClasspath }
generatorsJar { classpath = sourceSets.generators.compileClasspath }
defenseJar { classpath = sourceSets.defense.compileClasspath }
toolsJar { classpath = sourceSets.tools.compileClasspath }
allJar {}
}
task fullBuild(type: Delete) {
delete jar
dependsOn "build"
}
//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) }
}
}
}
}
//properties to put in $HOME/.gradle/gradle.properties
def MAVEN_PASSWORD_PROPERTY_NAME = 'mekanismMavenPassword'
def MAVEN_URL_PROPERTY_NAME = 'mekanismMavenUrl'
publishing {
publications {
maven(MavenPublication) {
from components.java
groupId = project.group
version = project.version
artifactId = project.archivesBaseName
artifacts = [apiJar, jar, generatorsJar, additionsJar, toolsJar, allJar]
pom {
groupId = project.group
version = project.version
if (System.getenv("MAVEN_ARTIFACT") != null) {
artifactId = System.getenv("MAVEN_ARTIFACT")
} else {
artifactId = project.archivesBaseName
}
name = "Mekanism"
packaging 'jar'
description 'Mekanism is a Minecraft add-on featuring high-tech machinery that can be used to create powerful tools, armor, and weapons.'
url = 'http://aidancbrady.com/mekanism/'
scm {
url = 'https://github.com/mekanism/Mekanism.git'
}
issueManagement {
system = 'github'
url = 'https://github.com/mekanism/Mekanism/issues'
}
licenses {
license {
name = 'MIT'
distribution = 'repo'
}
}
withXml {
NodeList dependencies = asNode().dependencies
NodeList allDeps = dependencies.'*'
// Remove forge deps
allDeps.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.findAll() { Node el ->
el.version.text().contains('_mapped_')
}.each { Node el ->
NodeList version = el.version
version.each {
it.setValue(it.text().substring(0, it.text().indexOf('_mapped_')))
}
el.appendNode('optional', true)
}
}
}
}
}
repositories {
maven {
if (project.findProperty(MAVEN_URL_PROPERTY_NAME) != null) {
url = project.findProperty(MAVEN_URL_PROPERTY_NAME)
}
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 ->
String message = commit.shortMessage
if (!message.startsWith("Merge branch") && !message.startsWith("Merge pull request")) {
//Ignore PRs and 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>"
})
if (generatedChangelog != "") {
generatedChangelog += "<br>"
}
generatedChangelog += "<a href=\"https://github.com/mekanism/Mekanism/commit/${commit.id}\">${commit.getAbbreviatedId()}</a> - ${message}\n"
}
}
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 "jei"
optionalDependency "ctm"
optionalDependency "biomes-o-plenty"
optionalDependency "flux-networks"
optionalDependency "hwyla"
optionalDependency "i-like-wood"
//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}"
}
}
}