forked from P3pp3rF1y/SophisticatedCore
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
544 lines (463 loc) · 19.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
import net.fabricmc.loom.task.ValidateMixinNameTask
import net.fabricmc.loom.util.gradle.SourceSetHelper
import net.fabricmc.loom.util.gradle.SourceSetReference
import com.github.salandora.sophisticatedcorebuild.SophisticatedCoreBuildPlugin;
buildscript {
repositories {
gradlePluginPortal()
maven { url = 'https://maven.parchmentmc.org' }
maven { url = "https://maven.fabricmc.net/" }
}
}
plugins {
id 'idea'
id 'fabric-loom' version '1.9.+'
id 'maven-publish'
id "net.darkhax.curseforgegradle" version "1.1.15"
id "com.modrinth.minotaur" version "2.+"
}
apply from: getProject().file('gradle/package-info.gradle')
apply plugin: SophisticatedCoreBuildPlugin
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
repositories {
mavenLocal()
mavenCentral()
maven {
name = 'ParchmentMC'
url = 'https://maven.parchmentmc.org'
}
maven { url = "https://maven.fabricmc.net/" } // FAPI, Loader
maven { url = "https://maven.quiltmc.org/repository/release" } // QM
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/Salandora/Porting-Lib")
credentials {
username = System.getenv("USERNAME")
password = System.getenv("READ_PACKAGES_TOKEN")
}
content {
includeGroupByRegex "io.github.fabricators_of_create.Porting-Lib.*"
}
}
maven { url = "https://mvn.devos.one/snapshots/" } // Create, Porting Lib
maven { url = "https://mvn.devos.one/releases/" } // Porting Lib
maven { // Forge Config API Port
name = "Fuzs Mod Resources"
url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/"
}
maven { url = "https://maven.nova-committee.cn/releases" } // Modern KeyBinding
maven { url = "https://maven.terraformersmc.com/releases/" } // Emi
maven { url = "https://maven.shedaniel.me/" } // REI and deps
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
maven {
name = "entity reach"
url = "https://maven.jamieswhiteshirt.com/libs-release/"
}
maven { url = "https://maven.ladysnake.org/releases" } // CCA, for Trinkets
maven { url = "https://www.cursemaven.com" } // Balm, CraftingTweaks
maven { url = "https://modmaven.dev" } // Jei
maven { url = "https://maven.resourcefulbees.com/repository/maven-public/" } // Chipped, resourcefullib, athena
}
group = mod_group_id
version = "${project.minecraft_version}-${project.mod_version}.${getBuildNumber()}${getStable()}"
logger.lifecycle("${project.name} version: ${project.version}")
base {
archivesName = "${mod_id}"
}
fabricApi {
configureDataGeneration {
setModId(project.mod_id)
setOutputDirectory(getProject().file("src/generated/resources")) // Set output directory to the same as the forge version
}
}
loom {
runtimeOnlyLog4j = true
accessWidenerPath = file ("src/main/resources/${mod_id}.accesswidener")
mods {
"${mod_id}" {
sourceSet sourceSets.main
}
}
runs {
client {
client()
configName = "Minecraft Client ${project.minecraft_version}"
runDir "run/${project.minecraft_version}"
property("mixin.debug.export=true") // export all mixins
property("mixin.debug.strict.unique=true") // strictly enforce that @Unique things are private
property("mixin.debug.countInjections=true")
vmArg("-XX:+AllowEnhancedClassRedefinition")
if (System.getenv("HOTSWAP_AGENT") != null) {
property("fabric.systemLibraries=" + System.getenv("HOTSWAP_AGENT"))
vmArg("--add-exports=java.base/sun.nio.ch=ALL-UNNAMED")
vmArg("--add-opens=java.base/java.lang=ALL-UNNAMED")
vmArg("--add-opens=java.base/java.lang.reflect=ALL-UNNAMED")
vmArg("--add-opens=java.base/java.io=ALL-UNNAMED")
vmArg("--add-opens=java.desktop/java.beans=ALL-UNNAMED")
vmArg("--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED")
}
try {
afterEvaluate {
def mixinDep = this.configurations.compileClasspath.incoming.artifactView {
componentFilter {
it instanceof ModuleComponentIdentifier
&& it.module == "sponge-mixin"
}
}
if (mixin != null) {
vmArg("-javaagent:${mixinDep.files.first().path}")
println("[Info]: Mixin Hotswap setup finished")
} else {
println("[Warning]: Unable to locate file path for Mixin jar")
}
}
} catch (Exception e) {
println("[Error]: Mixin Hotswap setup failed!")
e.printStackTrace()
}
}
server {
server()
configName = "Minecraft Server ${project.minecraft_version}"
runDir "run/${project.minecraft_version}"
}
}
}
configurations.all {
resolutionStrategy {
force "net.fabricmc:fabric-loader:$project.loader_version"
force "net.fabricmc.fabric-api:fabric-api:$project.fabric_version"
}
}
dependencies {
minecraft("com.mojang:minecraft:$project.minecraft_version")
mappings(loom.layered {
it.officialMojangMappings()
it.parchment("org.parchmentmc.data:parchment-${project.parchment_minecraft_version}:${project.parchment_mappings_version}@zip")
})
if (project.mixin_extras_version != "none") {
include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${mixin_extras_version}")))
}
// Fabric Loader
modImplementation("net.fabricmc:fabric-loader:$project.loader_version")
modImplementation("net.fabricmc.fabric-api:fabric-api:$project.fabric_version")
implementation("javax.annotation:javax.annotation-api:1.3.2")
implementation("com.google.code.findbugs:jsr305:3.0.2")
for (def module in porting_lib_modules.split(',')) {
modApi(include("io.github.fabricators_of_create.Porting-Lib:${module.trim()}:$porting_lib_version+$minecraft_version"))
}
// EMI
modCompileOnly("dev.emi:emi-fabric:$emi_version")
// JEI
//modCompileOnlyApi("mezz.jei:jei-$minecraft_version-common-api:$jei_version")
modCompileOnly("mezz.jei:jei-$minecraft_version-fabric:$jei_version")
// REI
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$rei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:$rei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}")
modApi(include("fuzs.forgeconfigapiport:forgeconfigapiport-fabric:$project.forge_config_api_port_version"))
modApi(include("teamreborn:energy:$project.energy_version"))
modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:$project.cloth_config_version")
modCompileOnly("curse.maven:jade-324717:${project.jade_version}")
modCompileOnly("curse.maven:litematica-308892:$project.litematica_cf_file_id")
modCompileOnly("curse.maven:malilib-303119:$project.malilib_cf_file_id")
modCompileOnly("curse.maven:craftingtweaks-502516:${project.crafting_tweaks_cf_file_id}")
modCompileOnly("curse.maven:balm-500525:${project.balm_cf_file_id}")
modCompileOnly("earth.terrarium.chipped:chipped-fabric-${minecraft_version}:${project.chipped_version}")
modCompileOnly("maven.modrinth:admiral:${admiral_version}")
modCompileOnly("maven.modrinth:simple-voice-chat:${simple_voice_chat_version}")
modCompileOnly("maven.modrinth:audioplayer:${audioplayer_version}")
modCompileOnly("dev.emi:trinkets:$project.trinkets_version")
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.+'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.+'
testImplementation "org.mockito:mockito-core:5.10.+"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.+'
}
test {
dependsOn("processResources")
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
tasks.register('validateMixinNames', ValidateMixinNameTask) {
source(sourceSets.main.output)
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
it.options.release = 21
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
jar {
from('/') {
include 'LICENSE'
}
manifest {
attributes([
'Specification-Title' : mod_id,
'Specification-Vendor' : "p3pp3rf1y",
'Specification-Version' : '1', // We are version 1 of ourselves
'Implementation-Title' : project.name,
'Implementation-Version' : project.jar.archiveVersion,
'Implementation-Vendor' : "p3pp3rf1y",
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
processResources {
var replaceProperties = [
mod_id : project.mod_id,
mod_name : project.mod_name,
mod_license : project.mod_license,
mod_version : version.replace(getStable(), ""), // remove the getStable string so that fabric loader can catch version mismatches, only important for snapshots
mod_issue_tracker_url: project.mod_issue_tracker_url,
mod_sources_url : project.mod_sources_url,
mod_logo_file : project.mod_logo_file,
mod_credits : project.mod_credits,
mod_description : project.mod_description,
mod_display_url : project.mod_display_url,
minecraft_version : project.minecraft_version,
loader_version : project.loader_version,
fabric_version : project.fabric_version,
forge_config_version: project.forge_config_api_port_version,
energy_version : project.energy_version,
jei_version : project.jei_version
]
inputs.properties replaceProperties
var mod_authors = []
for (String author in project.mod_authors.split(',')) {
mod_authors.add("\"${author.trim()}\"")
}
filesMatching("fabric.mod.json") {
expand replaceProperties + [project: project]
filter { String line ->
line = line.replace("[\"mod_authors\"]", mod_authors.toString())
line
}
}
}
// Fix to make IDEA load the correct resources when build and run is delegated to it
tasks.register('fixIntelliJResources', Copy) {
def ideaModuleCompileOutputPath = SourceSetHelper.getIdeaModuleCompileOutput(new SourceSetReference(sourceSets.main, project))
if (ideaModuleCompileOutputPath.empty)
return
dependsOn processResources
group "fabric"
from processResources
into ideaModuleCompileOutputPath[1]
}
static def getBuildNumber() {
if (System.getenv("GITHUB_RUN_NUMBER") != null) {
return System.getenv("GITHUB_RUN_NUMBER").toString()
}
return "9999"
}
static def getStable() {
if (System.getenv("GITHUB_REF") == null || System.getenv("GITHUB_REF").endsWith("-dev")) {
return "-SNAPSHOT"
}
return ""
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("${github_package_url}")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
register("mavenJava", MavenPublication) {
artifactId = mod_id
from((SoftwareComponent) components["java"])
}
}
}
tasks.register('generateChangelog') {
doLast {
// Function to remove characters with Unicode code points 129 or higher
def removeHighUnicodeChars = { text ->
text.codePoints()
.filter { codePoint -> codePoint <= 0x007F } // Keep only ASCII characters (U+0000 to U+007F)
.collect { codePoint -> new String(Character.toChars(codePoint)) }
.join('')
}
// Function to format commit messages with nesting
def formatMultilineMessage = { message ->
// Split message by lines, trim whitespace, and create formatted list
def lines = message.split('\n')
def formattedMessage = lines[0].trim() // First line as top-level list item
if (lines.size() > 1) {
formattedMessage += "\n" + lines[1..-1].collect { line ->
// Trim the line and remove leading dash if present
def trimmedLine = line.trim()
if (trimmedLine.startsWith('-')) {
trimmedLine = trimmedLine.substring(1).trim()
}
" - ${trimmedLine}" // Nested list for additional lines
}.join('\n')
}
return formattedMessage
}
// Function to remove [DEV] section from commit message
def removeDevSection = { message ->
def devIndex = message.indexOf('[DEV]')
if (devIndex != -1) {
return message.substring(0, devIndex).trim()
}
return message
}
// Get the latest commit hash
def latestCommitHash = "git rev-parse HEAD".execute().text.trim()
// Check if the latest commit is a merge commit
def parentCommits = "git rev-list --parents -n 1 ${latestCommitHash}".execute().text.split()
logger.info("Parent commits: ${parentCommits}")
def commitMessages = []
if (parentCommits.size() > 2) { // Merge commit has more than 2 parents
def firstParent = parentCommits[1]
def secondParent = parentCommits[2]
def gitLogCommand = [
"bash", "-c", "git log --pretty=format:%B ${firstParent}..${secondParent}"
]
commitMessages = gitLogCommand.execute().text.split('\n\n') // Split by two newlines for each commit
logger.info("Merge commit, ran git log command: ${gitLogCommand.join(' ')} and got ${commitMessages}")
} else {
// Single commit log
commitMessages = "git log -1 --pretty=%B".execute().text.split('\n\n')
// Split by two newlines for each commit
logger.info("Single commit, ran git log command: git log -1 --pretty=%B and got ${commitMessages}");
}
def generals = []
def features = []
def fixes = []
def compatibility = []
def mergedFeatures = []
def mergedFixes = []
def cleanup = false
commitMessages.each { String commitMessage ->
commitMessage = removeHighUnicodeChars(commitMessage) // Remove high Unicode characters
commitMessage = removeDevSection(commitMessage) // Remove [DEV] section
if (commitMessage.startsWith('[General]: ')) {
generals.add(commitMessage.replaceFirst('\\[General]: ', '').trim())
} else if (commitMessage.startsWith('[Feat]: ')) {
features.add(commitMessage.replaceFirst('\\[Feat]: ', '').trim())
} else if (commitMessage.startsWith('[Fix]: ')) {
fixes.add(commitMessage.replaceFirst('\\[Fix]: ', '').trim())
} else if (commitMessage.startsWith('[Compatibility]: ')) {
compatibility.add(commitMessage.replaceFirst('\\[Compatibility]: ', '').trim())
} else if (commitMessage.startsWith('[Cleanup]: ')) {
cleanup = true
} else if (commitMessage.startsWith('feat: ')) {
mergedFeatures.add(commitMessage.replaceFirst('feat: ', '').trim())
} else if (commitMessage.startsWith('fix: ')) {
mergedFixes.add(commitMessage.replaceFirst('fix: ', '').trim())
}
}
def changelog = new StringBuilder()
changelog.append("# Changelog\n\n")
changelog.append("### General\n")
changelog.append("- Update to version ${project.mod_version}\n")
if (cleanup) {
changelog.append("- Code cleanup\n")
}
if (generals) {
generals.each { general -> changelog.append("- ${formatMultilineMessage(general)}\n") }
}
changelog.append("\n")
if (features) {
changelog.append("### Features\n")
features.each { feature -> changelog.append("- ${formatMultilineMessage(feature)}\n") }
changelog.append("\n")
}
if (fixes) {
changelog.append("### Fixes\n")
fixes.each { fix -> changelog.append("- ${formatMultilineMessage(fix)}\n") }
changelog.append("\n")
}
if (compatibility) {
changelog.append("### Compatibility\n")
compatibility.each { comp -> changelog.append("- ${formatMultilineMessage(comp)}\n") }
changelog.append("\n")
}
if (mergedFeatures || mergedFixes) {
changelog.append("\n")
changelog.append("## Merged from upstream\n")
if (mergedFeatures) {
changelog.append("### Features\n")
mergedFeatures.each { feature -> changelog.append("- ${formatMultilineMessage(feature)}\n") }
changelog.append("\n")
}
if (mergedFixes) {
changelog.append("### Fixes\n")
mergedFixes.each { fix -> changelog.append("- ${formatMultilineMessage(fix)}\n") }
changelog.append("\n")
}
}
// Store the changelog in a project property or an environment variable
logger.info("Compiled changelog: " + changelog.toString())
project.ext.changelog = changelog.toString()
}
project.ext.changelog = ""
}
task curseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
dependsOn 'generateChangelog'
apiToken = System.getenv("CURSEFORGE_TOKEN")
def mainFile = upload(project.curseforge_id, file("${project.layout.buildDirectory.get()}/libs/${base.archivesName.get()}-${version}.jar"))
mainFile.changelogType = 'markdown'
mainFile.changelog = { project.ext.changelog }
mainFile.addModLoader('Fabric')
mainFile.releaseType = "${release_type}"
// Game versions
mainFile.addGameVersion("${release_versions}".split(','))
// Dependencies
mainFile.addRequirement('fabric-api')
mainFile.addEmbedded('forge-config-api-port-fabric')
mainFile.addEmbedded('porting-lib')
onlyIf { !project.ext.changelog.isEmpty() }
}
modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = "${modrinth_project_id}"
versionType = "${release_type}"
uploadFile = remapJar
gameVersions = "${release_versions}".split(',').collect {e -> e}
loaders = ["fabric"]
dependencies {
required.project "fabric-api"
embedded.project "forge-config-api-port"
embedded.project "porting_lib"
}
changelog = provider {
project.ext.changelog
}
}
tasks.modrinth {
dependsOn(tasks.generateChangelog)
onlyIf { !project.ext.changelog.isEmpty() }
}