-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
599 lines (498 loc) · 21.8 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/*
* This file is part of the Universal Mod Template
* licensed under the GNU GPL v3 License.
* (some parts of this file are originally from the Distant Horizons mod by James Seibel)
*
* Copyright (C) 2024 Leander Knüttel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* file changed by: Leander Knüttel
* date: 09.06.2024
*/
plugins {
id "java"
// Plugin to put dependencies inside our final jar
id "com.github.johnrengelman.shadow" version '8.1.1' apply false
// Plugin to create merged jars
id "io.github.pacifistmc.forgix" version "1.2.9"
// Manifold preprocessor
id "systems.manifold.manifold-gradle-plugin" version "0.0.2-alpha"
// Architectury is used here only as a replacement for forge's own loom
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
// Modpublisher: publish to Github, Modrinth and Curseforge in one go
id "com.hypherionmc.modutils.modpublisher" version "2.1.4"
}
/**
* Creates the list of preprocessors to use.
*
* @param mcVers array of all MC versions
* @param mcIndex array index of the currently active MC version
*/
def writeBuildGradlePredefine(List<String> mcVers, int mcIndex)
{
// Build the list of preprocessors to use
StringBuilder sb = new StringBuilder();
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n");
for (int i = 0; i < mcVers.size(); i++)
{
String verStr = mcVers[i].replace(".", "_");
sb.append("MC_" + verStr + "=" + i.toString() + "\n");
if (mcIndex == i)
sb.append("MC_VER=" + i.toString() + "\n");
}
// Check if this is a development build
if (mod_version.toLowerCase().contains("dev"))
{
// WARNING: only use this for logging, we don't want to have confusion
// when a method doesn't work correctly in the release build.
sb.append("DEV_BUILD=\n");
}
new File(projectDir, "build.properties").text = sb.toString()
}
// Transfers the values set in settings.gradle to the rest of the project
project.gradle.ext.getProperties().each { prop ->
rootProject.ext.set(prop.key, prop.value)
// println "Added prop [key:" + prop.key + ", value:" + prop.value + "]"
}
// Sets up manifold stuff
writeBuildGradlePredefine(rootProject.mcVers, rootProject.mcIndex)
// Sets up the version string (the name we use for our jar)
rootProject.versionStr = rootProject.mod_version + "-" + rootProject.file_name //+ rootProject.minecraft_version // + "-" + new Date().format("yyyy_MM_dd_HH_mm")
// Forgix settings (used for merging jars)
def mergeFabric = false
def mergeQuilt = false
def mergeForge = false
def mergeNeoForge = false
def mergeSpigot = false
if (rootProject.hasProperty("forgix_merge")){
for (loader in ((String) rootProject.forgix_merge).split(",")) {
def loaderName = loader.strip() // Strip it in case a space is added before or after the comma
println "Adding loader " + loaderName + " to Forgix Merge"
switch (loader){
case "fabric":
mergeFabric = true
break
case "quilt":
mergeQuilt = true
break
case "forge":
mergeForge = true
break
case "neoforge":
mergeNeoForge = true
break
case "spigot":
mergeSpigot = true
}
}
}
else{
println "Adding all loaders to Forgix Merge because nothing was specified!"
mergeFabric = true
mergeQuilt = true
mergeForge = true
mergeNeoForge = true
mergeSpigot = true
}
forgix {
group = rootProject.maven_group
mergedJarName = "${rootProject.mod_id}-${rootProject.versionStr}.jar"
if (findProject(":forge")) {
if (mergeForge) {
forge {
jarLocation = "build/libs/${rootProject.mod_id}-forge-${rootProject.versionStr}.jar"
mixin "${rootProject.mod_id}.forge.mixins.json"
}
}
else { // hack to not let it merge automatically
forge {
jarLocation = "invalid_build/libs/${rootProject.mod_id}-forge-${rootProject.versionStr}.jar"
}
}
}
// FIXME this breaks forge mixins
if (findProject(":neoforge")) {
if (mergeNeoForge){
neoforge {
jarLocation = "build/libs/${rootProject.mod_id}-neoforge-${rootProject.versionStr}.jar"
mixin "${rootProject.mod_id}.neoforge.mixins.json"
}
}
else { // hack to not let it merge automatically
neoforge {
jarLocation = "invalid_build/libs/${rootProject.mod_id}-neoforge-${rootProject.versionStr}.jar"
}
}
}
// FIXME this brakes neoforge mixins
//if (findProject(":neoforge")) {
// if (mergeNeoForge){
// custom {
// projectName = "neoforge"
// jarLocation = "build/libs/${rootProject.mod_id}-neoforge-${rootProject.versionStr}.jar"
// //mixin "${rootProject.mod_id}.neoforge.mixins.json"
// }
// }
// else { // hack to not let it merge automatically
// custom {
// projectName = "neoforge"
// jarLocation = "invalid_build/libs/${rootProject.mod_id}-neoforge-${rootProject.versionStr}.jar"
// //mixin "invalid_${rootProject.mod_id}.neoforge.mixins.json"
// }
// }
//}
if (findProject(":fabric")){
if (mergeFabric){
fabric {
jarLocation = "build/libs/${rootProject.mod_id}-fabric-${rootProject.versionStr}.jar"
}
}
else { // hack to not let it merge automatically
fabric {
jarLocation = "invalid_build/libs/${rootProject.mod_id}-fabric-${rootProject.versionStr}.jar"
}
}
}
if (findProject(":quilt")){
if (mergeQuilt){
quilt {
jarLocation = "build/libs/${rootProject.mod_id}-quilt-${rootProject.versionStr}.jar"
}
}
else{ // hack to not let it merge automatically
quilt {
jarLocation = "invalid_build/libs/${rootProject.mod_id}-quilt-${rootProject.versionStr}.jar"
}
}
}
if (findProject(":spigot")){
if (mergeSpigot){
custom {
projectName = "spigot"
jarLocation = "build/libs/${rootProject.mod_id}-spigot-${rootProject.versionStr}.jar"
}
}
}
removeDuplicate "${rootProject.maven_group}"
}
subprojects { p ->
// Does the same as "p == project(":common") || p == project(":fabric") || p == project(":quilt") || p == project(":forge") || p == project("WhateverWeAddLaterOn")"
// Useful later on so we dont have duplicated code
def isMinecraftSubProject = true//p != project(":core") && p != project(":api")
// Apply plugins
apply plugin: "java"
apply plugin: "com.github.johnrengelman.shadow"
if (isMinecraftSubProject){
apply plugin: "systems.manifold.manifold-gradle-plugin"
apply plugin: "com.hypherionmc.modutils.modpublisher"
}
// Apply forge's loom
if (
(findProject(":forge") && p == project(":forge")) ||
(findProject(":neoforge") && p == project(":neoforge"))
)
apply plugin: "dev.architectury.loom"
// Set the manifold version (may not be required tough)
manifold {
manifoldVersion = rootProject.manifold_version
}
// set up custom configurations (configurations are a way to handle dependencies)
configurations {
// extends the shadowJar configuration
shadowMe
// have implemented dependencies automatically embedded in the final jar
implementation.extendsFrom(shadowMe)
// Configuration fpr core & api
coreProjects
shadowMe.extendsFrom(coreProjects)
// FIXME this additional configuration is necessary because forge
// needs forgeRuntimeLibrary, although adding it to shadowMe
// causes runtime issues where the libraries aren't properly added
forgeShadowMe
// this should match shadowMe pretty closely
implementation.extendsFrom(forgeShadowMe)
shadowMe.extendsFrom(forgeShadowMe)
forgeRuntimeLibrary.extendsFrom(forgeShadowMe)
if (isMinecraftSubProject && p != project(":common")) {
// Shadow common
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
if (findProject(":forge"))
developmentForge.extendsFrom common
if (findProject(":neoforge"))
developmentNeoForge.extendsFrom common
compileClasspath.extendsFrom coreProjects
runtimeClasspath.extendsFrom coreProjects
if (findProject(":forge"))
developmentForge.extendsFrom coreProjects
if (findProject(":neoforge"))
developmentNeoForge.extendsFrom coreProjects
if (findProject(":fabricLike") && p != project(":fabricLike")) {
// Shadow fabricLike
fabricLike
shadowFabricLike
compileClasspath.extendsFrom fabricLike
runtimeClasspath.extendsFrom fabricLike
}
}
}
dependencies {
// Manifold
if (isMinecraftSubProject) {
annotationProcessor("systems.manifold:manifold-preprocessor:${rootProject.manifold_version}")
}
/////// ...left here as examples
// Log4j
//implementation("org.apache.logging.log4j:log4j-api:${rootProject.log4j_version}")
//implementation("org.apache.logging.log4j:log4j-core:${rootProject.log4j_version}")
// Remember, for lwjgl dependencies that arent included in Minecraft, you need to also need to add it to the ShadowJar thing
//forgeShadowMe("org.lwjgl:lwjgl-jawt:${rootProject.lwjgl_version}") {
// exclude group: "org.lwjgl", module: "lwjgl" // This module is imported by Minecraft so exclude it
//} // this is relocated down below...
///////
// Add common
if (isMinecraftSubProject && p != project(":common")) {
// Common
common(project(":common")) { transitive false }
shadowCommon(project(":common")) { transitive false }
// FabricLike
if (findProject(":fabricLike") && p != project(":fabricLike")) {
fabricLike(project(path: ":fabricLike")) { transitive false }
shadowFabricLike(project(path: ":fabricLike")) { transitive false }
}
}
}
shadowJar {
configurations = [project.configurations.shadowMe]
if (isMinecraftSubProject && p != project(":common")) {
configurations.push(project.configurations.shadowCommon) // Shadow the common subproject
//FIXME relocate "de.the_build_craft.example_mod.common", "loaderCommon.${p.name}.de.the_build_craft.example_mod.common" // Move the loader files to a different location
if (findProject(":fabricLike") && p != project(":fabricLike")) {
configurations.push(project.configurations.shadowFabricLike) // Shadow the fabricLike subproject
//FIXME relocate "de.the_build_craft.example_mod.fabriclike", "loaderCommon.${p.name}.de.the_build_craft.example_mod.fabriclike" // Move the loader files to a different location
}
}
def librariesLocation = rootProject.mod_id + ".libraries"
// Example Library to relocate
//relocate "org.lwjgl.system.jawt", "${librariesLocation}.lwjgl.system.jawt"
mergeServiceFiles()
}
// Using jar.finalizedBy(shadowJar) causes issues so we do this scuffed bypass
jar.dependsOn(shadowJar)
// Put stuff from gradle.properties into the mod info
processResources {
def resourceTargets = [ // Location of where to inject the properties
// Properties for each of the loaders
"fabric.mod.json",
"quilt.mod.json",
"META-INF/mods.toml",
"META-INF/neoforge.mods.toml",//for MC >= 1.20.5
"plugin.yml",
"pack.mcmeta",
// The mixins for each of the loaders
//rootProject.mod_id + "." + p.name + ".fabricLike.mixins.json" TODO ????
rootProject.mod_id + "." + p.name + ".mixins.json"
]
def intoTargets = ["$buildDir/resources/main/"] // Location of the built resources folder
// Fix forge version numbering system as it is weird
// For whatever reason forge uses [1.18, 1.18.1, 1.18.2) instead of the standard ["1.18", "1.18.1", "1.18.2"]
def compatible_forgemc_versions = "${compatible_minecraft_versions}".replaceAll("\"", "").replaceAll("]", ",)")
// println compatible_forgemc_versions
// Quilt's custom contributors system
// This has to be like
// "Person": "Developer", "Another person": "Developer"
def quilt_contributors = []
def mod_author_list = mod_authors.replaceAll("\"", "").replace("[", "").replace("]", "").split(",")
for (dev in mod_author_list) {
quilt_contributors.push("\"${dev.strip()}\": \"Developer\"")
}
quilt_contributors.reverse()
//println quilt_contributors.join(", ")
// TODO: Find something we can use so we can basically re-map only when the jar is shadowed and relocated
// println p.tasks.findByName('shadowJar')
// The left side is what gets replaced in the mod info and the right side is where to get it from in the gradle.properties
def replaceProperties = [
mod_id : mod_id,
version : mod_version,
mod_name : mod_name,
group : maven_group,
authors : mod_authors,
description : mod_description,
homepage : mod_homepage,
source : mod_source,
issues : mod_issues,
discord : mod_discord,
mod_license : mod_license,
neoforgeUpdateJSONURL : neoforgeUpdateJSONURL,
forgeUpdateJSONURL : forgeUpdateJSONURL,
minecraft_version : minecraft_version,
compatible_minecraft_versions: compatible_minecraft_versions,
compatible_forgemc_versions : compatible_forgemc_versions,
java_version : java_version,
quilt_contributors : "{"+quilt_contributors.join(", ")+"}",
fabric_incompatibility_list : fabric_incompatibility_list,
fabric_recommend_list : fabric_recommend_list,
spigot_api_compatibility : spigot_api_compatibility,
]
// replace any properties in the sub-projects with the values defined here
inputs.properties replaceProperties
replaceProperties.put "project", project
filesMatching(resourceTargets) {
expand replaceProperties
}
intoTargets.each { target ->
if (file(target).exists()) {
copy {
from(sourceSets.main.resources) {
include resourceTargets
expand replaceProperties
}
into target
}
}
}
// ==================== Delete un-needed files ====================
exclude rootProject.mod_id + ".fabricLike.mixins.json" // This isnt required atm, but we will be using it later
// exclude "*.example_mod.accesswidener"
//// include "${accessWidenerVersion}.example_mod.accesswidener"
// Jank solution to remove all unused accesswideners
// The line above would work..., except that (neo)forge (well, mainly architectury) requires the original accesswidener file, meaning we require this jank solution to keep it
exclude { file ->
if (file.name.contains(".${rootProject.mod_id}.accesswidener") && file.name != "${accessWidenerVersion}.${rootProject.mod_id}.accesswidener") {
return true
}
return false
}
}
}
allprojects { p ->
// Does the same as "p == project(":common") || p == project(":fabric") || p == project(":quilt") || p == project(":forge") || p == project("WhateverWeAddLaterOn")"
// Useful later on so we dont have duplicated code
def isMinecraftSubProject = true//p != project(":core") && p != project(":api")
apply plugin: "java"
apply plugin: "maven-publish"
archivesBaseName = rootProject.mod_id
version = project.name + "-" + rootProject.versionStr
group = rootProject.maven_group
// this is the text that appears at the top of the overview (home) page
// and is used when bookmarking a page
javadoc.title = rootProject.mod_id + "-" + project.name
// Some annotations arent "technically" part of the official java standard,
// so we define it ourself here
javadoc {
configure( options ) {
tags(
'todo:X"',
'apiNote:a:API Note:',
'implSpec:a:Implementation Requirements:',
'implNote:a:Implementation Note:'
)
}
}
repositories {
// The central repo
mavenCentral()
// Used for Google's Collect library
maven { url "https://repo.enonic.com/public/" }
// For parchment mappings
maven { url "https://maven.parchmentmc.org" }
// For Architectury API
maven { url "https://maven.architectury.dev" }
// For Git repositories
maven { url "https://jitpack.io" }
// For Manifold Preprocessor
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
// Required for importing Modrinth mods
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
// Required for importing CursedForge mods
maven {
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
// Required for ModMenu
maven { url "https://maven.terraformersmc.com/" }
// Required for ClothConfig
maven { url "https://maven.shedaniel.me/" }
// Required for Mixins & VanillaGradle
maven { url "https://repo.spongepowered.org/maven/" }
// These 4 are for importing mods that arnt on CursedForge, Modrinth, GitHub, GitLab or anywhere opensource
flatDir {
dirs "${rootDir}/mods/fabric"
content {
includeGroup "fabric-mod"
}
}
flatDir {
dirs "${rootDir}/mods/quilt"
content {
includeGroup "quilt-mod"
}
}
flatDir {
dirs "${rootDir}/mods/forge"
content {
includeGroup "forge-mod"
}
}
flatDir {
dirs "${rootDir}/mods/neoforge"
content {
includeGroup "neoforge-mod"
}
}
}
task copyCommonLoaderResources(type: Copy) {
from project(":common").file("src/main/resources/${accessWidenerVersion}.${rootProject.mod_id}.accesswidener")
into(file(p.file("build/resources/main")))
rename "${accessWidenerVersion}.${rootProject.mod_id}.accesswidener", "${rootProject.mod_id}.accesswidener"
// Move the fabricLike mixin to its different places for each subproject
if (findProject(":fabricLike")) {
from project(":fabricLike").file("src/main/resources/${rootProject.mod_id}.fabricLike.mixins.json")
into(file(p.file("build/resources/main")))
rename "${rootProject.mod_id}.fabricLike.mixins.json", "${rootProject.mod_id}." + p.name + ".fabricLike.mixins.json"
}
}
task copyCoreResources(type: Copy) {
from fileTree(project(":common").file("src/main/resources/assets"))
into p.file("build/resources/main/assets")
}
tasks.withType(JavaCompile) {
options.release = rootProject.java_version as Integer
options.compilerArgs += ["-Xplugin:Manifold"]
options.encoding = "UTF-8"
}
java {
withSourcesJar()
}
}
// Delete the merged folder when running clean
task cleanMergedJars() {
def mergedFolder = file("Merged")
if (mergedFolder.exists()) {
delete(mergedFolder)
}
}
// add cleanMergedJars to the end of the "clean" task
tasks["clean"].finalizedBy(cleanMergedJars)