-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbuild.gradle
888 lines (798 loc) · 32.5 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
// This file was adapted from the Mekanism project, obtained 19/8/22
// https://github.com/mekanism/Mekanism/blob/351554253dd69cbda96dfd6f00b8747b51122235/build.gradle
// Special thank you to pupnewfster (Sara) of the Mekanism Team
//
// Changes involve:
// replacing mod and sub-mod names, and using different mod dependencies and versions
// Changelog scraping via teamcity powershell script
// Setting up gradle with the ability to use mixins in all sourcesets [main,allomancy,feruchemy,hemalurgy,sandmastery,surgebinding]
// Removed jar that contains all mods in one, as I couldn't make it play nicely with mixins.
// That meant I didn't need the groovy-script MergeJars
//
import com.modrinth.minotaur.TaskModrinthUpload
import com.modrinth.minotaur.dependencies.ModDependency
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import net.darkhax.curseforgegradle.TaskPublishCurseForge
import net.darkhax.curseforgegradle.UploadArtifact
import net.minecraftforge.gradle.common.util.RunConfig
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace
buildscript {
repositories {
maven { url = 'https://repo.spongepowered.org/repository/maven-public' }
}
dependencies {
classpath group: 'org.spongepowered', name: 'mixingradle', version: '0.7-SNAPSHOT'
}
}
plugins {
id 'org.ajoberstar.grgit.service' version '5.2.0'
id 'net.darkhax.curseforgegradle' version '1.1.16'
id "com.modrinth.minotaur" version "2.+"
id 'java'
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
//id 'net.neoforged.gradle' version '[6.0.18,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'org.spongepowered.mixin' version '0.7.+'
}
tasks.named('wrapper', Wrapper).configure {
//Define wrapper values here so as to not have to always do so when updating gradlew.properties
gradleVersion = '8.4'
distributionType = Wrapper.DistributionType.ALL
}
defaultTasks 'build'
idea {
module {
//Exclude specific directories from being managed
for (String excludeDirName in ["run", "runGameTests", "out", "logs", "gradle"]) {
excludeDirs.add(new File(projectDir, excludeDirName))
}
}
}
def build_number = System.env.BUILD_NUMBER ?: 1
def full_mod_version = mod_version + "." + build_number
def release_type = System.env.TC_RELEASE_TYPE ?: "alpha"
ext {
secondaryModules = [
'allomancy',
'feruchemy',
'hemalurgy',
'surgebinding',
'sandmastery',
'awakening',
'aondor',
'aviar',
'soulforgery',
'example',
'cosmeretools']
extraTypes = ['datagen', 'gameTest']
jsonPatterns = ["**/*.json", "**/*.mcmeta"]
//version properties here automatically update versions in all the mods.toml files
//we want that because updating every time something changes is tedious
versionProperties = [
"version" : full_mod_version,
"mc_version" : minecraft_version_range,
"forge_version" : forge_version_range,
"loader_version" : loader_version_range,
"patchouli_version": patchouli_version_range,
"jade_version" : jade_version_range,
"jei_version" : jei_version_range,
"curios_version" : curios_version_range
]
}
sourceSets {
api {
//API is code only and does not have 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/cosmere']
//But exclude the cache of the generated data from what gets built
exclude '.cache'
}
compileClasspath += api.output
runtimeClasspath += api.output
}
test {
//The test module has no resources
resources.srcDirs = []
//Add the api to the output, all other ones that need to will get added via setupExtraSourceSets
compileClasspath += api.output
runtimeClasspath += api.output
}
}
//Add all extra source sets that the main sourceSet should have
setupExtraSourceSets(sourceSets.main)
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)
extendConfigurations(compileOnly, apiCompileOnly, testCompileOnly)
extendConfigurations(runtimeOnly, apiRuntimeOnly)
}
//Create sourceSets and configurations for each of the additional modules 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 cosmere
// module to the dependencies of the source set we are setting up, and sets up all extra source sets that are
// based on the primary added source set
for (def name : secondaryModules) {
def sourceSet = sourceSets.create(name)
sourceSet.resources {
//Add the generated module resources
srcDirs += ["src/datagen/generated/${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
//Create all secondary sourceSets for this module
setupExtraSourceSets(sourceSet)
}
//Setup the UPDATE_SOURCESET property in case we are doing any remappings
project.ext."UPDATE_SOURCESETS" = project.sourceSets.collect { it.name }.join(';')
def setupExtraSourceSets(SourceSet base)
{
project.sourceSets.test.compileClasspath += base.output
project.sourceSets.test.runtimeClasspath += base.output
//Setup and extend configurations for alternate modules. First by making the implementation, compileOnly, runtimeOnly equivalents
// for those modules extend the main ones
def baseImplementation = project.configurations.maybeCreate(base.getTaskName(null, "implementation"))
def baseCompileOnly = project.configurations.maybeCreate(base.getTaskName(null, "compileOnly"))
def baseRuntimeOnly = project.configurations.maybeCreate(base.getTaskName(null, "runtimeOnly"))
if (base != project.sourceSets.main) {
// If this is a secondary module then make the base tasks extend the builtin ones
baseImplementation.extendsFrom(project.configurations.getByName("implementation"))
baseCompileOnly.extendsFrom(project.configurations.getByName("compileOnly"))
baseRuntimeOnly.extendsFrom(project.configurations.getByName("runtimeOnly"))
}
//And then setup and have all the extra sourceSets have their configurations extend the ones for the base module so that they can
// properly access the dependency
for (String extraType : extraTypes) {
//Setup a source set in extraType/$name
def extraSourceSet = setupExtraSourceSet(base, extraType)
//And then setup the configurations for it
project.configurations.maybeCreate(extraSourceSet.getTaskName(null, "implementation")).extendsFrom(baseImplementation)
project.configurations.maybeCreate(extraSourceSet.getTaskName(null, "compileOnly")).extendsFrom(baseCompileOnly)
project.configurations.maybeCreate(extraSourceSet.getTaskName(null, "runtimeOnly")).extendsFrom(baseRuntimeOnly)
}
}
SourceSet setupExtraSourceSet(SourceSet baseSourceSet, String extra)
{
def name = baseSourceSet.getName()
def extraSourceSet = sourceSets.create(baseSourceSet.getTaskName(extra, null))
extraSourceSet.java.srcDirs = ["src/${extra}/${name}/java"]
//Resources folder for if we have anything get created by our annotation processors or in the case of game tests, for any nbt presets
extraSourceSet.resources.srcDirs = ["src/${extra}/${name}/resources"]
extraSourceSet.compileClasspath += project.sourceSets.api.output
extraSourceSet.compileClasspath += project.sourceSets.main.output
if (baseSourceSet != project.sourceSets.main) {
//If the base sourceSet is main it already is the extra source set and has a reference to the base one from before this if statement
extraSourceSet.compileClasspath += getExtraSourceSet(project.sourceSets.main, extra).output
extraSourceSet.compileClasspath += baseSourceSet.output
}
return extraSourceSet
}
static void extendConfigurations(Configuration base, Configuration... configurations)
{
for (def configuration : configurations) {
configuration.extendsFrom(base)
}
}
SourceSet getExtraSourceSet(String base, String name)
{
return getExtraSourceSet(project.sourceSets.getByName(base), name)
}
SourceSet getExtraSourceSet(SourceSet base, String name)
{
return project.sourceSets.getByName(base.getTaskName(name, null))
}
//Update book build number
processResources {
// Exclude datagenerator .cache directory
exclude '.cache'
filesMatching('data/cosmere/patchouli_books/guide/book.json') {
filter {
it.replaceAll("buildNumber", "${build_number}")
}
}
}
setupTasks(sourceSets.main)
for (def name : secondaryModules) {
setupTasks(sourceSets.getByName(name))
}
def setupTasks(SourceSet sourceSet)
{
def sourceSetName = sourceSet.name
def compileTask = tasks.named(sourceSet.getCompileJavaTaskName(), JavaCompile)
def replaceResourceTask = tasks.register(sourceSet.getTaskName("replace", "resources"), Copy, {
setGroup("replace resources")
outputs.upToDateWhen { false }
def modsToml = copySpec {
from(sourceSet.resources) {
include "META-INF/mods.toml"
expand versionProperties
}
}
def packMcMeta = copySpec {
from(sourceSet.resources) {
include "pack.mcmeta"
// I don't want to auto-replace pack format values since I don't want
// to adopt the datagen core mod pack filter suppressor in mekanism
//expand packProperties
}
}
//Copy it into the build dir
with(modsToml, packMcMeta)
into "$buildDir/resources/${sourceSetName}/"
//If IntelliJ's output dir exists, copy it there as well
def intellijPath = sourceSet == project.sourceSets.main ? "production" : sourceSetName
if (new File("$rootDir/out/${intellijPath}/resources/").exists()) {
copy {
with(modsToml, packMcMeta)
into "$rootDir/out/${intellijPath}/resources/"
}
}
//If Eclipse's output dir exists, copy it there as well
if (new File("$rootDir/bin/${sourceSetName}/").exists()) {
copy {
with(modsToml, packMcMeta)
into "$rootDir/bin/${sourceSetName}/"
}
}
})
//Set the various variables/settings for the different process resources tasks
tasks.named(sourceSet.getProcessResourcesTaskName(), ProcessResources).configure {
setGroup("process resources")
duplicatesStrategy(DuplicatesStrategy.FAIL)
exclude('META-INF/mods.toml', 'pack.mcmeta')
from("${projectDir}") { include 'logo.png' }
//Depend on the compile task so that we can map the computer methods as needed
dependsOn(compileTask)
finalizedBy(replaceResourceTask)
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file)))
}
}
}
tasks.named(sourceSet.getCompileJavaTaskName(), JavaCompile).configure { setGroup("compile") }
for (def extraType : extraTypes) {
def extraSourceSet = getExtraSourceSet(sourceSet, extraType)
tasks.named(extraSourceSet.getProcessResourcesTaskName(), ProcessResources).configure {
setGroup("process resources")
dependsOn(compileTask)
}
tasks.named(extraSourceSet.getCompileJavaTaskName(), JavaCompile).configure { setGroup("compile") }
}
//Make the various classes tasks depend on the corresponding replaceResources tasks in addition to the default processResources tasks they depend on
tasks.named(sourceSet.getClassesTaskName()).configure { dependsOn(replaceResourceTask) }
}
archivesBaseName = "Cosmere"
group = 'leaf.cosmere'
version = "${minecraft_version}-${forge_version}-" + full_mod_version
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of("${java_version}"))
//vendor.set(JvmVendorSpec.JETBRAINS)
}
withSourcesJar()
}
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {
mappings channel: "${mappings_channel}", version: "${mappings_version}"
accessTransformers.from(file('src/main/resources/META-INF/accesstransformer.cfg'),
file('src/allomancy/resources/META-INF/accesstransformer.cfg'),
file('src/surgebinding/resources/META-INF/accesstransformer.cfg'))
runs {
client {
setupRunConfig(it, true)
//The below if statements are to add args to your gradle.properties file in user home
// (for me on windows, I created gradle.properties in %userprofile%\.gradle)
// (DO NOT add them directly to the gradle.properties file for this project)
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')
}
}
server { setupRunConfig(it, true) }
gameTestServer { setupRunConfig(it, true, "runGameTests") }
data {
setupRunConfig(it, false)
environment 'target', 'fmluserdevdata'
args '--all', '--output', file('src/datagen/generated/'),
'--mod', 'cosmere', '--existing', file('src/main/resources/')
mods.named("cosmere").configure { source((SourceSet) sourceSets.datagenMain) }
for (def name : secondaryModules) {
def modName = "${name}"
def extra = getExtraSourceSet(name, 'datagen')
mods.named(modName).configure { source(extra) }
args '--mod', modName, '--existing', file("src/${name}/resources/")
}
}
}
}
def setupRunConfig(RunConfig runConfig, boolean supportsGameTests, String directory = "run")
{
runConfig.workingDirectory(file(directory))
//This fixes Mixin application problems from other mods because their refMaps are SRG-based, but we're in a MCP env
runConfig.property 'mixin.env.remapRefMap', 'true'
runConfig.property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
if (supportsGameTests) {
//Specify all our mods as domains to look for game tests
runConfig.property 'forge.enabledGameTestNamespaces', 'cosmere,allomancy,feruchemy,hemalurgy,surgebinding,sandmastery,cosmeretools'
}
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
runConfig.jvmArg("-Dterminal.ansi=${project.getProperty('forge_force_ansi')}")
}
runConfig.mods.register("cosmere").configure {
sources((SourceSet[]) [sourceSets.main, sourceSets.api])
if (supportsGameTests) source((SourceSet) sourceSets.gameTestMain)
}
for (def name : secondaryModules) {
def base = sourceSets.getByName(name)
def extra = supportsGameTests ? getExtraSourceSet(base, 'gameTest') : null
runConfig.mods.register("${name}").configure {
source(base)
if (supportsGameTests) source(extra)
}
}
}
repositories {
maven {
// location of the maven that hosts JEI files
url "https://dvs1.progwml6.com/files/maven/"
}
maven {
//used for patchouli
url "https://maven.blamejared.com/"
}
maven {
//curio
url "https://maven.theillusivec4.top/"
}
maven {
//curios
url 'https://modmaven.dev/'
}
maven {
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
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'
excludeGroup 'top.theillusivec4.curios'
excludeGroup 'vazkii.patchouli'
}
println("Adding exclusions to ${url}")
} catch (Exception ignored) {
//oh well
}
}
}
}
}
dependencies {
//minecraft "net.neoforged:forge:${minecraft_version}-${forge_version}"
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
apiAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
allomancyAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
feruchemyAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
hemalurgyAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
surgebindingAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
sandmasteryAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
aviarAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
awakeningAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
aondorAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
soulforgeryAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
cosmeretoolsAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}")
compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}")
runtimeOnly fg.deobf("mezz.jei:jei-${minecraft_version}-forge:${jei_version}")
compileOnly fg.deobf("curse.maven:jade-api-324717:${jade_api_id}")
runtimeOnly fg.deobf("curse.maven:jade-324717:${jade_id}")
//runtimeOnly fg.deobf("curse.maven:soulhome-574511:${soulhome_id}")
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}")
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api")
compileOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}-FORGE:api")
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}-FORGE")
}
mixin {
// MixinGradle Settings
add sourceSets.main, 'mixins.cosmere.refmap.json'
add sourceSets.api, 'mixins.cosmere.api.refmap.json'
add sourceSets.allomancy, 'mixins.cosmere.allomancy.refmap.json'
add sourceSets.feruchemy, 'mixins.cosmere.feruchemy.refmap.json'
add sourceSets.hemalurgy, 'mixins.cosmere.hemalurgy.refmap.json'
add sourceSets.surgebinding, 'mixins.cosmere.surgebinding.refmap.json'
add sourceSets.sandmastery, 'mixins.cosmere.sandmastery.refmap.json'
add sourceSets.aviar, 'mixins.cosmere.aviar.refmap.json'
add sourceSets.awakening, 'mixins.cosmere.awakening.refmap.json'
add sourceSets.aondor, 'mixins.cosmere.aondor.refmap.json'
add sourceSets.soulforgery, 'mixins.cosmere.soulforgery.refmap.json'
add sourceSets.cosmeretools, 'mixins.cosmere.cosmeretools.refmap.json'
config 'cosmere.mixins.json'
//config 'cosmere.mixins.api.json'
config 'allomancy.mixins.json'
config 'feruchemy.mixins.json'
config 'hemalurgy.mixins.json'
config 'surgebinding.mixins.json'
config 'sandmastery.mixins.json'
config 'aviar.mixins.json'
config 'awakening.mixins.json'
config 'aondor.mixins.json'
config 'soulforgery.mixins.json'
config 'cosmeretools.mixins.json'
}
def getManifestAttributes(String title)
{
return [
"Specification-Title" : title,
"Specification-Vendor" : "Cosmere",
"Specification-Version" : "${project.ext.versionProperties["version"]}",
"Implementation-Title" : title,
"Implementation-Version" : "${project.ext.versionProperties["version"]}",
"Implementation-Vendor" : "Cosmere",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"Automatic-Module-Name" : title.toLowerCase(Locale.ROOT),
"MixinConfigs" : "${title.toLowerCase(Locale.ROOT)}.mixins.json"
]
}
tasks.named('jar', Jar).configure {
duplicatesStrategy(DuplicatesStrategy.FAIL)
from([sourceSets.api.output, sourceSets.main.output])
manifest.attributes(getManifestAttributes("Cosmere"))
}
tasks.named('sourcesJar', Jar).configure {
dependsOn(
classes,
apiClasses,
allomancyClasses,
feruchemyClasses,
hemalurgyClasses,
surgebindingClasses,
sandmasteryClasses,
aviarClasses,
awakeningClasses,
aondorClasses,
soulforgeryClasses,
cosmeretoolsClasses,
)
duplicatesStrategy(DuplicatesStrategy.FAIL)
//Note: Already contains main source set's sources by default
from(
sourceSets.api.allJava,
sourceSets.allomancy.allJava,
sourceSets.feruchemy.allJava,
sourceSets.hemalurgy.allJava,
sourceSets.surgebinding.allJava,
sourceSets.sandmastery.allJava,
sourceSets.aviar.allJava,
sourceSets.awakening.allJava,
sourceSets.aondor.allJava,
sourceSets.soulforgery.allJava,
sourceSets.cosmeretools.allJava,
)
manifest.attributes(getManifestAttributes("Cosmere"))
}
def secondaryJar(SourceSet sourceSet, String title)
{
return tasks.register(sourceSet.getJarTaskName(), Jar, {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set(sourceSet.name)
from sourceSet.output
if (!title.isEmpty()) {
def filename = "${title}-${project.version}.jar"
//basically don't add cosmere if it already has cosmere in it
final def prependTitle = (title.contains("Cosmere") ? "" : "Cosmere") + filename
archiveFileName.set(prependTitle)
}
manifest.attributes(getManifestAttributes(title.isEmpty() ? "Cosmere" : title))
})
}
def apiJar = secondaryJar(sourceSets.api, '')
def allomancyJar = secondaryJar(sourceSets.allomancy, 'Allomancy')
def feruchemyJar = secondaryJar(sourceSets.feruchemy, 'Feruchemy')
def hemalurgyJar = secondaryJar(sourceSets.hemalurgy, 'Hemalurgy')
def surgebindingJar = secondaryJar(sourceSets.surgebinding, 'Surgebinding')
def sandmasteryJar = secondaryJar(sourceSets.sandmastery, 'Sandmastery')
def awakeningJar = secondaryJar(sourceSets.awakening, 'Awakening')
def aondorJar = secondaryJar(sourceSets.aondor, 'AonDor')
def aviarJar = secondaryJar(sourceSets.aviar, 'Aviar')
def soulforgeryJar = secondaryJar(sourceSets.soulforgery, 'SoulForgery')
def exampleJar = secondaryJar(sourceSets.example, 'Example')
def cosmeretoolsJar = secondaryJar(sourceSets.cosmeretools, 'CosmereTools')
tasks.withType(JavaCompile).configureEach({
options.encoding = 'UTF-8'
options.compilerArgs.addAll(["-Xmaxerrs", "100000"])
})
artifacts {
archives apiJar
archives jar
archives allomancyJar
archives hemalurgyJar
archives feruchemyJar
archives surgebindingJar
archives sandmasteryJar
archives sourcesJar
archives awakeningJar
archives aondorJar
archives aviarJar
archives soulforgeryJar
archives exampleJar
archives cosmeretoolsJar
}
createReobf(sourceSets.api)
for (def name : secondaryModules) {
createReobf(sourceSets.getByName(name))
}
def createReobf(SourceSet sourceSet)
{
def reobfTask = createReobf(sourceSet.getJarTaskName())
reobfTask.configure { libraries.from(sourceSet.compileClasspath) }
tasks.named(sourceSet.getJarTaskName()).configure(task -> task.finalizedBy(reobfTask))
return reobfTask
}
def createReobf(String name)
{
def reobfExtension = (NamedDomainObjectContainer<RenameJarInPlace>) extensions.getByName("reobf")
//using maybeCreate instead of Register, as mixin environment gets confused.
return reobfExtension.maybeCreate(name)
}
afterEvaluate {
tasks.named('jar', Jar).configure { finalizedBy(tasks.named('reobfJar', RenameJarInPlace)) }
}
tasks.withType(GenerateModuleMetadata) {
//Disable Gradle 7 module metadata generation as it does not play nicely with FG
enabled = false
}
clean {
def filteredDelete = new HashSet<>()
for (def toDelete : getDelete()) {
for (def f : file(toDelete).listFiles()) {
if (f.getName() == "generated") {
for (def generated : file(f).listFiles()) {
if (generated.getName() != "data" && generated.getName() != "META-INF") {
filteredDelete.add(generated)
}
}
} else if (f.getName() != "fg_cache") {
filteredDelete.add(f)
}
}
}
setDelete(filteredDelete)
}
def resolvedChangelog = null
//closure to generate the changelog once, and only when needed by CurseGradle
def changeLogResolver = { ->
String generatedChangelog;
//autogenerated log via teamcity, which uses a generic powershell script to generate a changelog
def autogeneratedChangelog = project.file("docs/changelog_Cosmere_${build_number}.txt")
if (autogeneratedChangelog.exists()) {
//Add any version specific changelog stuff
def changelogText = autogeneratedChangelog.getText()
generatedChangelog = "$changelogText"
} else {
generatedChangelog = "Unable to generate changelog :("
}
//add hand written log to put at the top
def releaseNotesFile = project.file("docs/release_${build_number}.txt")
if (releaseNotesFile.exists()) {
//Add any version specific changelog stuff
def releaseNotes = releaseNotesFile.getText()
generatedChangelog = "$releaseNotes \n\n $generatedChangelog"
}
generatedChangelog =
"Cosmere and related sub module mods are considered to be in an alpha state! You have been warned :)" +
"\n\n$generatedChangelog"
resolvedChangelog = generatedChangelog
return generatedChangelog
}
if (System.getenv("CURSEFORGE_API_TOKEN") != null || project.hasProperty('curseforge_api_token')) {
println "Enabling Curseforge config"
tasks.register("curseforge", TaskPublishCurseForge, { task ->
setGroup("publishing")
setDescription("Upload to CurseForge")
apiToken = System.getenv("CURSEFORGE_API_TOKEN") ?: project.findProperty("curseforge_api_token")
def changelog = changeLogResolver.call()
//Main Project
task.upload(475343, jar) { main ->
setGenericCurseArtifactData(main, changelog, release_type)
//Include the API jar as a secondary file to the main file
withAdditionalFile(apiJar)
//Add optional deps
addOptional(
'jade',
'curios',
'patchouli',
'jei',
'allomancer',
'feruchemist',
'hemalurgy',
'surgebinding',
'sandmastery',
'aviar',
'cosmere-tools'
)
}
//Secondary modules/projects
uploadSecondaryCurseProject(task, 678468, changelog, allomancyJar, release_type)
uploadSecondaryCurseProject(task, 678466, changelog, feruchemyJar, release_type)
uploadSecondaryCurseProject(task, 678469, changelog, hemalurgyJar, release_type)
uploadSecondaryCurseProject(task, 624998, changelog, surgebindingJar, release_type)
uploadSecondaryCurseProject(task, 695387, changelog, sandmasteryJar, release_type)
uploadSecondaryCurseProject(task, 822584, changelog, aviarJar, release_type)
uploadSecondaryCurseProject(task, 990661, changelog, cosmeretoolsJar, release_type)
//not yet ready
//uploadSecondaryCurseProject(task, 822581, changelog, aondorJar)
//uploadSecondaryCurseProject(task, 822580, changelog, awakeningJar)
//uploadSecondaryCurseProject(task, 822593, changelog, soulforgeryJar)
//uploadSecondaryCurseProject(task, 822596, changelog, bloodsealingJar)
})
}
void setGenericCurseArtifactData(UploadArtifact artifact, String changelog, String release_type)
{
artifact.changelog = changelog
artifact.changelogType = 'text'
artifact.releaseType = "${release_type}"
artifact.addModLoader("Forge")
artifact.addModLoader("NeoForge")
}
void uploadSecondaryCurseProject(TaskPublishCurseForge task, long projectId, String changelog, TaskProvider<Jar> sourceSetJar, String release_type)
{
task.upload(projectId, sourceSetJar) { artifact ->
setGenericCurseArtifactData(artifact, changelog, release_type)
addRequirement('cosmere')
addOptional(
'jade',
'curios',
'patchouli',
'jei',
'allomancer',
'feruchemist',
'hemalurgy',
'surgebinding',
'sandmastery',
'aviar',
'cosmere-tools'
)
addIncompatibility(
'hemalurgy-lego-allomancy'
)
}
}
if (System.getenv("MODRINTH_API_TOKEN") != null || project.hasProperty('modrinth_api_token')) {
println "Enabling Modrinth config"
def allomancyModrinth = createSecondaryModrinthUpload("allomancy", "u1pejmgA", allomancyJar)
def feruchemyModrinth = createSecondaryModrinthUpload("feruchemy", "OX40vFNo", feruchemyJar)
def hemalurgyModrinth = createSecondaryModrinthUpload("hemalurgy", "McOcm9tD", hemalurgyJar)
def surgebindingModrinth = createSecondaryModrinthUpload("surgebinding", "ohwrIsCO", surgebindingJar)
def sandmasteryModrinth = createSecondaryModrinthUpload("sandmastery", "9EJFLSYm", sandmasteryJar)
def aviarModrinth = createSecondaryModrinthUpload("aviar", "75FFkvaX", aviarJar)
def cosmeretoolsModrinth = createSecondaryModrinthUpload("tools", "T0u6rdso", cosmeretoolsJar)
//not yet ready
//def aondorModrinth = createSecondaryModrinthUpload("aondor", "E92whAPB", aondorJar)
//def awakeningModrinth = createSecondaryModrinthUpload("awakening", "WZZ5m3YI", awakeningJar)
//def soulforgeryModrinth = createSecondaryModrinthUpload("soulforgery", "26ErEJqz", soulforgeryJar)
//def bloodsealingModrinth = createSecondaryModrinthUpload("bloodsealing", "lmdH7wUj", bloodsealingJar)
tasks.named('modrinth').configure {
dependsOn(jar, apiJar)
finalizedBy(
allomancyModrinth,
feruchemyModrinth,
hemalurgyModrinth,
surgebindingModrinth,
sandmasteryModrinth,
aviarModrinth,
cosmeretoolsModrinth
)
}
modrinth {
if (System.getenv("MODRINTH_API_TOKEN") == null) {
//Defaults to modrinth_api_token so we only have to check for a token via gradle properties if there isn't a system property
getToken().value((String) project.findProperty("modrinth_api_token"))
} else {
token = System.getenv("MODRINTH_API_TOKEN")
}
projectId = "SEABTDiK"
versionNumber = "${full_mod_version}"
versionType = "${release_type}"
loaders.addAll("forge", "neoforge")
gameVersions = ["1.20.1"] // Must be an array, even with only one version
changelog = changeLogResolver.call()
uploadFile = jar
getAdditionalFiles().value([apiJar.get()])
//Note: Can't use nested dependency configuration as we have no way to clear it for the secondary uploads
getDependencies().value([
new ModDependency("vvuO3ImH", "required"),//Curios
new ModDependency("nU0bVIaL", "optional"),//Patchouli
new ModDependency("nvQzSEkH", "optional"),//Jade
new ModDependency("u6dRKJwZ", "optional"),//JEI
new ModDependency("u1pejmgA", "optional"),//allomancy
new ModDependency("OX40vFNo", "optional"),//feruchemy
new ModDependency("McOcm9tD", "optional"),//hemalurgy
new ModDependency("ohwrIsCO", "optional"),//surgebinding
new ModDependency("9EJFLSYm", "optional"),//sandmastery
new ModDependency("75FFkvaX", "optional"),//aviar
new ModDependency("T0u6rdso", "optional"),//cosmeretools
])
}
}
def createSecondaryModrinthUpload(String output, String targetProjectId, TaskProvider<Jar> sourceSetJar)
{
return tasks.register("${output}Modrinth", TaskModrinthUpload, {
setGroup("publishing")
setDescription("Upload ${output} to Modrinth")
dependsOn(tasks.named("modrinth"), sourceSetJar)
doFirst {
//Run in do first to change the configured extension values before it starts applying
modrinth {
projectId = targetProjectId
uploadFile = sourceSetJar.get()
gameVersions = ["1.20.1"] // Must be an array, even with only one version
//Clear additional upload files as this is a modification of what things are set to from before
getAdditionalFiles().empty()
//Mark that the addon requires the build of Cosmere that we just uploaded (and override it to clear all optional dependencies)
//todo fix this because it doesn't appear to work anymore. fails on .getId() as some other version is null??
/* def generalCosmereDependency =
(tasks.modrinth.newVersion == null || tasks.modrinth.newVersion.getId() == null) //If we failed to find the upload version
// just set it to Cosmere in general
? new ModDependency("SEABTDiK", "required")
// else use the specific version
: new VersionDependency(tasks.modrinth.newVersion.getId(), "required")*/
getDependencies().value([
new ModDependency("SEABTDiK", "required"),//generalCosmereDependency,
new ModDependency("vvuO3ImH", "required"),//Curios
new ModDependency("nU0bVIaL", "optional"),//Patchouli
new ModDependency("nvQzSEkH", "optional"),//Jade
new ModDependency("u6dRKJwZ", "optional"),//JEI
new ModDependency("u1pejmgA", "optional"),//allomancy
new ModDependency("OX40vFNo", "optional"),//feruchemy
new ModDependency("McOcm9tD", "optional"),//hemalurgy
new ModDependency("ohwrIsCO", "optional"),//surgebinding
new ModDependency("9EJFLSYm", "optional"),//sandmastery
new ModDependency("75FFkvaX", "optional"),//aviar
new ModDependency("T0u6rdso", "optional"),//cosmeretools
])
}
println "Updated Modrinth extension"
}
})
}
tasks.register('publishToModSites') {
if (System.getenv("MODRINTH_API_TOKEN") != null || project.hasProperty('modrinth_api_token')) {
publishToModSites.dependsOn tasks.named("modrinth")
}
if (System.getenv("CURSEFORGE_API_TOKEN") != null || project.hasProperty('curseforge_api_token')) {
publishToModSites.dependsOn tasks.named("curseforge")
}
}