-
-
Notifications
You must be signed in to change notification settings - Fork 529
/
build.gradle
751 lines (682 loc) · 35.2 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
import com.modrinth.minotaur.TaskModrinthUpload
import com.modrinth.minotaur.dependencies.ModDependency
import com.modrinth.minotaur.dependencies.VersionDependency
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import mekanism.AllJar
import mekanism.MergeModuleResources
import mekanism.OptimizePng
import mekanism.OutputChangelog
import net.darkhax.curseforgegradle.TaskPublishCurseForge
import net.darkhax.curseforgegradle.UploadArtifact
import java.util.function.Consumer
plugins {
id('org.ajoberstar.grgit.service')//Version declared in buildSrc
id('net.darkhax.curseforgegradle') version('1.1.25')
id('com.modrinth.minotaur') version('2.8.7')
id('java')
id('eclipse')
id('idea')
id('maven-publish')
id('net.neoforged.gradle.userdev') version('7.0.154')//https://projects.neoforged.net/neoforged/neogradle
}
tasks.named('wrapper', Wrapper).configure {
//Define wrapper values here so as to not have to always do so when updating gradlew.properties
gradleVersion = '8.10'
distributionType = Wrapper.DistributionType.ALL
}
defaultTasks('build')
idea {
module {
//Exclude directories from being managed
for (String excludeDirName : ['runs', 'out', 'logs', 'gradle']) {
excludeDirs.add(file(excludeDirName))
}
//Tell IDEA to always download sources/javadoc artifacts from maven.
downloadJavadoc = true
downloadSources = true
}
}
ext {
secondaryModules = ['additions', 'generators', 'tools']
extraTypes = ['datagen']
}
sourceSets {
api {
//The API has no resources
resources.srcDirs = []
}
main {
resources {
include('**/**')
// copy everything else, but blender and bbmodel files.
// And also exclude the cache of the generated data from what gets built
exclude('**/*.blend', '**/*.bbmodel', '.cache')
//Add the generated main module resources
srcDirs += ['src/datagen/generated/mekanism']
}
compileClasspath += 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
}
gameTest {
runs.modIdentifier = 'mekanismtests'
compileClasspath += api.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 neo
extendConfigurations(implementation, apiImplementation, testImplementation)
extendConfigurations(compileOnly, apiCompileOnly, testCompileOnly)
extendConfigurations(runtimeOnly, apiRuntimeOnly)
extendConfigurations(localRuntime, apiLocalRuntime)
datagenNonMod
}
//Add all extra source sets that the main sourceSet should have
setupExtraSourceSets(sourceSets.main)
setupExtraSourceSets(sourceSets.gameTest, false)
//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 mekanism
// 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 (String name : secondaryModules) {
def sourceSet = sourceSets.create(name)
sourceSet.runs.modIdentifier = 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
//Create all secondary sourceSets for this module
setupExtraSourceSets(sourceSet)
}
def setupExtraSourceSets(SourceSet base, boolean includeExtra = true) {
//Expose the base module to junit
project.sourceSets.test.compileClasspath += base.output
if (base != project.sourceSets.gameTest) {
project.sourceSets.gameTest.compileClasspath += 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'))
def baseLocalRuntime = project.configurations.maybeCreate(base.getTaskName(null, 'localRuntime'))
if (base != project.sourceSets.main) {
// If this is a secondary module then make the base tasks extend the builtin ones
baseImplementation.extendsFrom(project.configurations.named('implementation').get())
baseCompileOnly.extendsFrom(project.configurations.named('compileOnly').get())
baseRuntimeOnly.extendsFrom(project.configurations.named('runtimeOnly').get())
baseLocalRuntime.extendsFrom(project.configurations.named('localRuntime').get())
}
if (includeExtra) {
//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
def implExtends = [baseImplementation]
if (extraType == 'datagen') {
implExtends.add(project.configurations.named('datagenNonMod').get())
}
project.configurations.maybeCreate(extraSourceSet.getTaskName(null, 'implementation')).extendsFrom(*implExtends)
project.configurations.maybeCreate(extraSourceSet.getTaskName(null, 'compileOnly')).extendsFrom(baseCompileOnly)
project.configurations.maybeCreate(extraSourceSet.getTaskName(null, 'runtimeOnly')).extendsFrom(baseRuntimeOnly)
project.configurations.maybeCreate(extraSourceSet.getTaskName(null, 'localRuntime')).extendsFrom(baseLocalRuntime)
}
}
}
SourceSet setupExtraSourceSet(SourceSet baseSourceSet, String extra) {
def name = baseSourceSet.name
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).get().output
extraSourceSet.compileClasspath += baseSourceSet.output
extraSourceSet.runs.modIdentifier = name
}
return extraSourceSet
}
static void extendConfigurations(Configuration base, Configuration... configurations) {
for (def configuration : configurations) {
configuration.extendsFrom(base)
}
}
Provider<SourceSet> getExtraSourceSet(String base, String name) {
return project.sourceSets.named(base).flatMap(sourceSet -> getExtraSourceSet(sourceSet, name))
}
Provider<SourceSet> getExtraSourceSet(SourceSet base, String name) {
return project.sourceSets.named(base.getTaskName(name, null))
}
setupTasks(sourceSets.main)
for (String name : secondaryModules) {
setupTasks(sourceSets.named(name).get())
}
def setupTasks(SourceSet sourceSet) {
def compileTask = tasks.named(sourceSet.compileJavaTaskName, JavaCompile)
//Set the various variables/settings for the different process resources tasks
tasks.named(sourceSet.processResourcesTaskName, ProcessResources).configure { ProcessResources process ->
process.setGroup('process resources')
process.duplicatesStrategy(DuplicatesStrategy.FAIL)
var versionProperties = ['version': mod_version, 'mc_version': minecraft_version_range, 'forge_version': forge_version_range, 'loader_version': loader_version_range,
'jei_version': jei_version_range]
//Mark the properties as inputs so that when they change things update
process.inputs.properties(versionProperties)
process.filesMatching('META-INF/neoforge.mods.toml') { expand(versionProperties) }
process.from("${projectDir}") { include('logo.png') }
//Depend on the compile task so that we can map the computer methods as needed
process.dependsOn(compileTask)
def files = fileTree(dir: outputs.files.asPath, includes: ['**/*.json', '**/*.mcmeta'])
process.doLast {
for (def file : files) {
file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}
tasks.named(sourceSet.compileJavaTaskName, JavaCompile).configure { setGroup('compile') }
for (String extraType : extraTypes) {
def extraSourceSet = getExtraSourceSet(sourceSet, extraType).get()
tasks.named(extraSourceSet.processResourcesTaskName, ProcessResources).configure {
setGroup('process resources')
dependsOn(compileTask)
}
tasks.named(extraSourceSet.compileJavaTaskName, JavaCompile).configure { setGroup('compile') }
}
//Configure specific compile tasks to have the proper annotation processor info
compileTask.configure { JavaCompile task ->
setGroup('compile')
task.options.annotationProcessorPath = configurations.annotationProcessor
task.options.compilerArgs.addAll([
"-AmekanismModule=mekanism${sourceSet == sourceSets.main ? '' : sourceSet.name}",//annotation processor param
'-parameters'
])
}
}
group = 'mekanism'
def basicVersion = "${mod_version}." + (System.getenv('BUILD_NUMBER') ?: 'homebaked')
version = "${minecraft_version}-${basicVersion}"
project.base.archivesName = 'Mekanism'
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of("${java_version}"))
vendor.set(JvmVendorSpec.JETBRAINS)
}
withSourcesJar()
}
minecraft.accessTransformers.files(
file('src/main/resources/META-INF/accesstransformer.cfg'),
file('src/additions/resources/META-INF/accesstransformer.cfg'),
//Dev time only ATs so the file name doesn't have to match accesstransformer.cfg
file('src/datagen/main/resources/META-INF/datagen_ats.cfg'),
file('src/gameTest/resources/META-INF/gametest_ats.cfg')
)
runs {
configureEach {
if (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
systemProperties.put('terminal.ansi', (String) property('forge_force_ansi'))
}
modSources.add((SourceSet[]) [sourceSets.main, sourceSets.api])
for (String name : secondaryModules) {
modSources.add((SourceSet) sourceSets.named(name).get())
}
//if the selected toolchain is a JBR, enable DCEVM
if (javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse('').contains('JetBrains')) {
jvmArguments.add('-XX:+AllowEnhancedClassRedefinition')
}
}
//Note: To enable logging into the client account, set the neogradle.subsystems.devLogin.conventionForRun property to true in your gradle user home
// https://github.com/neoforged/NeoGradle?tab=readme-ov-file#per-run-configuration
client {
}
clientAlt {
configure('client')
//Force disable devLogin for clientAlt regardless of if it is enabled via gradle properties for the main gradle run
devLogin.enabled(false)
if (!(findProperty('neogradle.subsystems.devLogin.conventionForRun') ?: false)) {
//If the property is missing or set to false (so the normal runClient task would use Dev as the name),
// change the name of the alt client type so that it doesn't conflict with the main dev one
programArguments.addAll((String[]) ['--username', 'AltDev'])
}
}
server {
}
gameTestServer {
modSources.add((SourceSet) sourceSets.gameTest)
}
gameTestClient {
configure('client')
modSources.add((SourceSet) sourceSets.gameTest)
}
junit {
unitTestSources.add((SourceSet) sourceSets.test)
}
data {
programArguments.addAll((String[]) ['--all', '--output', file('src/datagen/generated/').absolutePath,
'--mod', 'mekanism', '--existing', file('src/main/resources/').absolutePath])
modSources.add((SourceSet) sourceSets.datagenMain)
for (String name : secondaryModules) {
modSources.add(getExtraSourceSet(name, 'datagen').get())
programArguments.addAll((String[]) ['--mod', "mekanism${name}", '--existing', file("src/${name}/resources/").absolutePath])
}
dependencies {
runtime(configurations.datagenNonMod)
}
}
}
static void exclusiveRepo(RepositoryHandler handler, String url, String... groups) {
exclusiveRepo(handler, url, filter -> {
for (def group : groups) {
filter.includeGroup(group)
}
})
}
static void exclusiveRepo(RepositoryHandler handler, String url, Consumer<InclusiveRepositoryContentDescriptor> filterSetup) {
handler.exclusiveContent {
it.forRepositories(handler.maven {
setUrl(url)
})
it.filter { f -> filterSetup.accept(f) }
}
}
repositories { RepositoryHandler handler ->
exclusiveRepo(handler, 'https://maven.blamejared.com', filter -> {
filter.includeGroupByRegex('com\\.blamejared.*')
filter.includeGroup('mezz.jei')
filter.includeGroup('org.openzen.zencode')
})
exclusiveRepo(handler, 'https://maven.terraformersmc.com/', 'dev.emi')
exclusiveRepo(handler, 'https://maven.octo-studios.com/releases/', 'top.theillusivec4.curios')
exclusiveRepo(handler, 'https://maven.tterrag.com/', 'team.chisel.ctm')
exclusiveRepo(handler, 'https://squiddev.cc/maven/', 'cc.tweaked', 'org.squiddev')
exclusiveRepo(handler, 'https://dogforce-games.com/maven/', 'dev.gigaherz.jsonthings')
exclusiveRepo(handler, 'https://maven2.bai.lol', 'lol.bai', 'mcp.mobius.waila')//WTHIT
exclusiveRepo(handler, 'https://www.cursemaven.com', 'curse.maven')
exclusiveRepo(handler, 'https://modmaven.dev/', 'appeng', 'mcjty.theoneprobe', 'dev.technici4n')
exclusiveRepo(handler, 'https://maven.minecraftforge.net/releases/', 'com.github.glitchfiend')
exclusiveRepo(handler, 'https://maven.thiakil.com', 'com.thiakil', 'moze_intel')
exclusiveRepo(handler, 'https://maven.parchmentmc.org/', 'org.parchmentmc.data')
}
tasks.named('test').configure {
//Disable builtin test task as we use and build uses testJunit so there is no point in having it also attempt to run an empty test task
enabled(false)
}
dependencies {
implementation("net.neoforged:neoforge:${forge_version}")
compileOnly(project(':annotation-processor'))
localRuntime(project(':annotation-processor'))
annotationProcessor(project(':annotation-processor'))
def testFrameWork = "net.neoforged:testframework:${forge_version}"
gameTestImplementation(testFrameWork)
testImplementation(testFrameWork)
testImplementation("org.junit.jupiter:junit-jupiter-api:${junit_version}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junit_version}")
//We use https://github.com/jqwik-team/jqwik to allow for implementing property based testing
testImplementation("net.jqwik:jqwik:${jqwik_version}")
compileOnly("mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}")
if (recipe_viewer == 'jei' || recipe_viewer == 'hybrid') {
localRuntime("mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}")
}
compileOnly("dev.emi:emi-neoforge:${emi_version}+${previous_minor_minecraft_version}:api")
def emi = "dev.emi:emi-neoforge:${emi_version}+${previous_minor_minecraft_version}"
//TODO: Re-evaluate (https://github.com/emilyploszaj/emi/issues/537) might allow us to not have to do this
//Compile against full emi in datagen
datagenMainCompileOnly(emi)
if (recipe_viewer == 'emi' || recipe_viewer == 'hybrid') {
localRuntime(emi)
} else {
//We still need it to load in datagen regardless of if we are using emi or a different viewer so that we can access EMI related objects
datagenMainRuntimeOnly(emi)
}
localRuntime("team.chisel.ctm:CTM:${previous_minor_minecraft_version}-${ctm_version}")
compileOnly("mcjty.theoneprobe:theoneprobe:${top_version}:api")
localRuntime("mcjty.theoneprobe:theoneprobe:${top_version}")
compileOnly("curse.maven:jade-api-324717:${jade_api_id}")
localRuntime("curse.maven:jade-324717:${jade_id}")
compileOnly("mcp.mobius.waila:wthit-api:neo-${wthit_version}")
//localRuntime("mcp.mobius.waila:wthit:neo-${wthit_version}")
//localRuntime('lol.bai:badpackets:neo-0.8.1')
def crt = "com.blamejared.crafttweaker:CraftTweaker-neoforge-${minecraft_version}:${crafttweaker_version}"
compileOnly(crt)
localRuntime(crt)
def jeiTweaker = "com.blamejared.jeitweaker:JeiTweaker-forge-1.20.1:${jeitweaker_version}"
compileOnly(jeiTweaker)
//TODO: Re-enable when it updates
//localRuntime(jeiTweaker)
compileOnly("dev.gigaherz.jsonthings:JsonThings-${previous_minor_minecraft_version}:${json_things_version}")
//Mods we have dependencies on but don't bother loading into the dev environment
//compileOnly("curse.maven:projecte-api-226410:${projecte_api_id}")
compileOnly('moze_intel:ProjectE-api:1.0.1')
compileOnly("curse.maven:flux-networks-248020:${flux_networks_id}")
compileOnly("dev.technici4n:GrandPower:${grand_power_version}")
compileOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}:api")
compileOnly("com.blamejared.recipestages:RecipeStages:${recipe_stages_version}")
compileOnly("curse.maven:opencomputers2-437654:${oc2_id}")
compileOnly("cc.tweaked:cc-tweaked-${previous_minor_minecraft_version}-forge-api:${cc_tweaked_version}")
//localRuntime("cc.tweaked:cc-tweaked-${previous_minor_minecraft_version}-forge:${cc_tweaked_version}")
compileOnly("curse.maven:female-gender-forge-481655:${wildfire_gender_mod_id}")
compileOnly("curse.maven:framedblocks-441647:${framedblocks_mod_id}")
//Dependencies for data generators for mod compat reference
datagenMainImplementation("appeng:appliedenergistics2:${ae2_version}")
datagenMainRuntimeOnly("com.github.glitchfiend:GlitchCore-neoforge:${previous_minor_minecraft_version}-${glitchcore_version}")
datagenMainRuntimeOnly("com.github.glitchfiend:TerraBlender-neoforge:${previous_minor_minecraft_version}-${terrablender_version}")
datagenMainImplementation("com.github.glitchfiend:BiomesOPlenty-neoforge:${previous_minor_minecraft_version}-${biomesoplenty_version}")
//TODO: Switch back to datagenMainImplementation after it doesn't crash when default components are modified in datagen
datagenMainCompileOnly("curse.maven:farmers-delight-398521:${farmers_delight_id}")
//TODO - 1.20.2: Re-enable after projecte is updated
//datagenMainRuntimeOnly("curse.maven:projecte-226410:${projecte_id}")
datagenNonMod("com.thiakil:yaml-ops:${yamlops_version}")
}
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"),
'Automatic-Module-Name' : title.toLowerCase(Locale.ROOT)
]
}
tasks.named('jar', Jar).configure { Jar jar ->
jar.duplicatesStrategy(DuplicatesStrategy.FAIL)
jar.from([sourceSets.api.output, sourceSets.main.output])
jar.exclude('crafttweaker_parameter_names.json')
jar.manifest.attributes(getManifestAttributes('Mekanism'))
}
tasks.named('sourcesJar', Jar).configure { Jar jar ->
dependsOn(classes, apiClasses, additionsClasses, generatorsClasses, toolsClasses)
jar.duplicatesStrategy(DuplicatesStrategy.FAIL)
//Note: Already contains main source set's sources by default
jar.from(sourceSets.api.allJava, sourceSets.additions.allJava, sourceSets.generators.allJava, sourceSets.tools.allJava)
jar.manifest.attributes(getManifestAttributes('Mekanism'))
}
def secondaryJar(SourceSet sourceSet, String title) {
return tasks.register(sourceSet.jarTaskName, Jar, {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set(sourceSet.name)
from(sourceSet.output)
if (!title.isEmpty()) {
archiveFileName.set("${title}-${project.version}.jar")
}
manifest.attributes(getManifestAttributes(title.isEmpty() ? 'Mekanism' : title))
})
}
def apiJar = secondaryJar(sourceSets.api, '')
def additionsJar = secondaryJar(sourceSets.additions, 'MekanismAdditions')
def generatorsJar = secondaryJar(sourceSets.generators, 'MekanismGenerators')
def toolsJar = secondaryJar(sourceSets.tools, 'MekanismTools')
def mergeModuleResources = tasks.register('mergeModuleResources', MergeModuleResources, {
dependsOn('classes', 'apiClasses', 'additionsClasses', 'generatorsClasses', 'toolsClasses')
mustRunAfter('clean')
//Note: Get the resources from the output of process resources, so that any expands that need to happen we know have already happened
resources = tasks.named(sourceSets.main.processResourcesTaskName).get().outputs.files
//Note: We have to use classesDirs rather than generatedSourcesDirs to also include resources generated by the annotation process
// and not just the java source files. We filter further along to ensure we only take services into account
annotationGenerated = sourceSets.main.output.classesDirs
for (String name : secondaryModules) {
SourceSet secondarySourceSet = sourceSets.named(name).get()
resources += tasks.named(secondarySourceSet.processResourcesTaskName).get().outputs.files
annotationGenerated += secondarySourceSet.output.classesDirs
}
//Only look at generated service files as a restriction for our input
annotationGenerated = annotationGenerated.asFileTree.matching(serviceFilter)
})
def allJar = tasks.register('allJar', AllJar, {
dependsOn(mergeModuleResources)
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set('all')
manifest.attributes(getManifestAttributes('MekanismAll'))
pathsToExclude.set(mergeModuleResources.flatMap(m -> m.pathsToExclude))
apiOutput = sourceSets.api.output
mainOutput = sourceSets.main.output
for (String name : secondaryModules) {
secondaryModuleOutputs += sourceSets.named(name).get().output
}
})
tasks.withType(JavaCompile).configureEach({
options.encoding = 'UTF-8'
options.compilerArgs.addAll(['-Xmaxerrs', '100000'])
})
tasks.withType(Javadoc).configureEach({
options.encoding = 'UTF-8'
options.tags = [
'apiNote:a:<em>API Note:</em>',
'implSpec:a:<em>Implementation Requirements:</em>',
'implNote:a:<em>Implementation Note:</em>'
]
})
artifacts {
archives apiJar
archives jar
archives additionsJar
archives generatorsJar
archives toolsJar
archives allJar
archives sourcesJar
}
tasks.register('optimizePng', OptimizePng) {
def pngPatterns = ['**/*.png']
//Ensure the logo is minimized (we add this file to each jar)
inputFiles.from(file("${projectDir}/logo.png"))
//Minimize any PNGs in the source sets
def sourceSets = [sourceSets.main, sourceSets.additions, sourceSets.generators, sourceSets.tools]
for (def sourceSet : sourceSets) {
for (def dir : sourceSet.resources.srcDirs) {
inputFiles.from(fileTree(dir: dir, includes: pngPatterns))
}
}
//TODO: Make optimize png be fully compatible with the configuration cache?
notCompatibleWithConfigurationCache('Up to date check is not currently compatible with the configuration cache')
outputs.upToDateWhen {
//Validate that none of the files has changed size, as the odds that a file has the exact same size and has changed is very low for an image file
//Note: This is from Chat-GPT, I don't understand why the any check isn't just always true (and thus this being different from returning always false)
// but it seems to function properly(?), whereas just always returning false does not
!inputFiles.files.any { file -> file.length() != file.size() }
}
}
//properties to put in $HOME/.gradle/gradle.properties
def MAVEN_PASSWORD_PROPERTY_NAME = 'mekanismMavenPassword'
def MODMAVEN_PW = System.getenv('MEK_MAVEN_PW') ?: (String) project.findProperty(MAVEN_PASSWORD_PROPERTY_NAME)
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.base.archivesName.get()
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')
}
}
}
}
}
repositories {
maven {
url = 'https://modmaven.dev/artifactory/local-releases/'
if (MODMAVEN_PW != null) {
credentials {
username = 'mekanism'
password = MODMAVEN_PW
}
}
}
}
}
def outputChangelog = tasks.register('outputChangelog', OutputChangelog, grgitService.service)
outputChangelog.configure { OutputChangelog out ->
out.releaseNotes.value(provider {
//If we have a file specified that exists for the mod version, then we want to use it
// otherwise we want to fall back to not having the value set
def file = layout.projectDirectory.file("docs/release_${mod_version}.md")
return file.asFile.exists() ? file : null
})
}
if (System.getenv('CURSEFORGE_KEY') != null || project.hasProperty('curseforgeKey')) {
logger.lifecycle('Enabling Curseforge config')
tasks.register('curseforge', TaskPublishCurseForge, { task ->
dependsOn(outputChangelog)
setGroup('publishing')
setDescription('Upload Mekanism to CurseForge')
def changelog = outputChangelog.flatMap(c -> c.outputFile)
inputs.file(changelog)
inputs.property('release_type', release_type)
inputs.property('java_version', java_version)
inputs.property('minecraft_version', minecraft_version)
disableVersionDetection()
apiToken = System.getenv('CURSEFORGE_KEY') ?: project.findProperty('curseforgeKey')
//Main Mekanism Project
def mainCfUpload = task.upload(268560, jar) { main ->
setGenericCurseArtifactData(main, changelog)
//Include the API jar as a secondary file to the main file
withAdditionalFile(apiJar)
//Add optional deps
addOptional(
//Computers
'cc-tweaked', 'oc2',
//Looking at mods
'jade', 'the-one-probe', 'wthit-forge',
//Recipe viewers
'emi', 'jei',
//Tweakers
'crafttweaker', 'jeitweaker',
//World gen
'biomes-o-plenty',
//Misc
'applied-energistics-2', 'ctm', 'curios-continuation', 'dark-mode-everywhere', 'farmers-delight', 'female-gender-forge', 'flux-networks',
'framedblocks', 'grandpower', 'json-things', 'perviaminvenire', 'projecte', 'recipe-stages'
)
}
//Secondary modules/projects
def additionsCfUpload = uploadSecondaryCurseProject(task, 345425, changelog, additionsJar)
def generatorsCfUpload = uploadSecondaryCurseProject(task, 268566, changelog, generatorsJar)
def toolsCfUpload = uploadSecondaryCurseProject(task, 268567, changelog, toolsJar)
doLast {
//Note: Quiet is the level above warning but below error. We want these to show regardless of logging level
// see: https://docs.gradle.org/current/userguide/logging.html
//Note: We cast to object to be explicit, so that when we have CurseForgeGradle in debug mode and these are null
// then it can resolve which overload to use
logger.quiet('https://www.curseforge.com/minecraft/mc-mods/mekanism/files/{}', (Object) mainCfUpload.curseFileId)
logger.quiet('https://www.curseforge.com/minecraft/mc-mods/mekanism-additions/files/{}', (Object) additionsCfUpload.curseFileId)
logger.quiet('https://www.curseforge.com/minecraft/mc-mods/mekanism-generators/files/{}', (Object) generatorsCfUpload.curseFileId)
logger.quiet('https://www.curseforge.com/minecraft/mc-mods/mekanism-tools/files/{}', (Object) toolsCfUpload.curseFileId)
}
})
}
void setGenericCurseArtifactData(UploadArtifact artifact, Provider<RegularFile> changelog) {
artifact.changelog = changelog
artifact.changelogType = 'markdown'
artifact.releaseType = release_type
artifact.addModLoader('NeoForge')
artifact.addJavaVersion("Java ${java_version}")
artifact.addGameVersion(minecraft_version)
}
UploadArtifact uploadSecondaryCurseProject(TaskPublishCurseForge task, long projectId, Provider<RegularFile> changelog, TaskProvider<Jar> sourceSetJar) {
return task.upload(projectId, sourceSetJar) { artifact ->
setGenericCurseArtifactData(artifact, changelog)
addRequirement('mekanism')
}
}
if (System.getenv('MODRINTH_TOKEN') != null || project.hasProperty('modrinthToken')) {
logger.lifecycle('Enabling Modrinth config')
def additionsModrinth = createSecondaryModrinthUpload('additions', 'a6F3uASn', additionsJar)
def generatorsModrinth = createSecondaryModrinthUpload('generators', 'OFVYKsAk', generatorsJar)
def toolsModrinth = createSecondaryModrinthUpload('tools', 'tqQpq1lt', toolsJar)
tasks.named('modrinth').configure {
dependsOn(jar, apiJar, outputChangelog)
finalizedBy(additionsModrinth, generatorsModrinth, toolsModrinth)
notCompatibleWithConfigurationCache('Not yet compatible')//TODO: Remove when possible
}
modrinth {
if (System.getenv('MODRINTH_TOKEN') == null) {
//Defaults to MODRINTH_TOKEN so we only have to check for a token via gradle properties if there isn't a system property
token.set((String) project.findProperty('modrinthToken'))
} else {
token = System.getenv('MODRINTH_TOKEN')
}
projectId = 'Ce6I4WUE'
//Use the full "basic" version number rather than just mod version number so that if multiple releases end up happening due to bugs
// then we don't run into conflicts in uploading
//Note: The versionName is set to the versionNumber automatically
versionNumber = "${basicVersion}"
versionType = "${release_type}"
gameVersions.add("${minecraft_version}")
loaders.add('neoforge')
failSilently = true
changelog.value(outputChangelog.flatMap(c -> c.outputFile).map(file -> file.asFile.text))
uploadFile = jar
additionalFiles.value([apiJar.get()])
//Note: Can't use nested dependency configuration as we have no way to clear it for the secondary uploads
dependencies.value([
new ModDependency('XxWD5pD3', 'optional'),//AE2
new ModDependency('gu7yAYhd', 'optional'),//CC: Tweaked
new ModDependency('Xg35A4rS', 'optional'),//CraftTweaker
new ModDependency('fRiHVvU7', 'optional'),//EMI
new ModDependency('R2OftAxM', 'optional'),//Farmer's Delight
new ModDependency('nvQzSEkH', 'optional'),//Jade
new ModDependency('u6dRKJwZ', 'optional'),//JEI
new ModDependency('EiEOyeoL', 'optional'),//JEI Tweaker
new ModDependency('qXkLFB0L', 'optional'),//Recipe Stages
new ModDependency('Eyw0UxEx', 'optional'),//The One Probe
new ModDependency('bcOsQHnC', 'optional'),//Wildfire's Female Gender Mod
new ModDependency('6AQIaxuO', 'optional'),//WTHIT
])
}
}
def createSecondaryModrinthUpload(String output, String targetProjectId, TaskProvider<Jar> sourceSetJar) {
return tasks.register("${output}Modrinth", TaskModrinthUpload, {
setGroup('publishing')
setDescription("Upload Mekanism ${output} to Modrinth")
dependsOn(tasks.named('modrinth'), sourceSetJar)
notCompatibleWithConfigurationCache('Not yet compatible')//TODO: Remove when possible
doFirst {
//Run in do first to change the configured extension values before it starts applying
modrinth {
projectId = targetProjectId
uploadFile = sourceSetJar.get()
//Clear additional upload files as this is a modification of what things are set to from before
additionalFiles.empty()
//Mark that the addon requires the build of Mekanism that we just uploaded (and override it to clear all optional dependencies)
if (tasks.modrinth.newVersion == null || tasks.modrinth.newVersion.getId() == null) {
//If we failed to find the upload version just set it to Mekanism in general
dependencies.value([new ModDependency('Ce6I4WUE', 'required')])
} else {
dependencies.value([new VersionDependency((String) tasks.modrinth.newVersion.getId(), 'required')])
}
}
logger.lifecycle('Updated Modrinth extension')
}
})
}