-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle.kts
590 lines (495 loc) · 16.2 KB
/
build.gradle.kts
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
import groovy.xml.XmlSlurper
import org.codehaus.groovy.runtime.ResourceGroovyMethods
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.net.URI
import java.nio.file.Files
import java.util.*
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("org.kohsuke:github-api:+")
}
}
plugins {
id("fabric-loom") version("+")
id("org.ajoberstar.grgit") version("+")
id("org.quiltmc.gradle.licenser") version("+")
id("com.modrinth.minotaur") version("+")
id("com.github.johnrengelman.shadow") version("+")
`maven-publish`
eclipse
idea
`java-library`
java
kotlin("jvm") version("2.0.21")
}
val minecraft_version: String by project
val quilt_mappings: String by project
val parchment_mappings: String by project
val loader_version: String by project
val min_loader_version: String by project
val mod_version: String by project
val mod_loader: String by project
val maven_group: String by project
val archives_base_name: String by project
val fabric_api_version: String by project
val fabric_kotlin_version: String by project
val fabric_asm_version: String by project
val toml4j_version: String by project
val jankson_version: String by project
val xjs_data_version: String by project
val xjs_compat_version: String by project
val fresult_version: String by project
val modmenu_version: String by project
val cloth_config_version: String by project
val copperpipes_version: String by project
val terrablender_version: String by project
val sodium_version: String by project
val iris_version: String by project
val indium_version: String by project
val sodium_extra_version: String by project
val reeses_sodium_options_version: String by project
val lithium_version: String by project
val fastanim_version: String by project
val ferritecore_version: String by project
val lazydfu_version: String by project
val starlight_version: String by project
val entityculling_version: String by project
val memoryleakfix_version: String by project
val no_unused_chunks_version: String by project
val ksyxis_version: String by project
val githubActions: Boolean = System.getenv("GITHUB_ACTIONS") == "true"
val licenseChecks: Boolean = githubActions
base {
archivesName.set(archives_base_name)
}
version = getModVersion()
group = maven_group
val release = findProperty("releaseType")?.equals("stable")
val testmod by sourceSets.registering {
runtimeClasspath += sourceSets.main.get().runtimeClasspath
compileClasspath += sourceSets.main.get().compileClasspath
}
loom {
runtimeOnlyLog4j.set(true)
runs {
register("testmodClient") {
client()
ideConfigGenerated(project.rootProject == project)
name("Testmod Client")
source(testmod.get())
}
register("testmodServer") {
server()
ideConfigGenerated(project.rootProject == project)
name("Testmod Server")
source(testmod.get())
}
named("client") {
ideConfigGenerated(true)
}
named("server") {
ideConfigGenerated(true)
}
}
mixin {
defaultRefmapName = "mixins.frozenlib.refmap.json"
}
accessWidenerPath = file("src/main/resources/frozenlib.accesswidener")
interfaceInjection {
// When enabled, injected interfaces from dependecies will be applied.
enableDependencyInterfaceInjection = true
}
}
sourceSets {
testmod {
resources {
srcDirs("src/testmod/generated")
}
}
}
loom {
runs {
register("testmodDatagen") {
client()
name("Testmod Data Generation")
source(testmod.get())
vmArg("-Dfabric-api.datagen")
vmArg("-Dfabric-api.datagen.output-dir=${file("src/testmod/generated")}")
//vmArg("-Dfabric-api.datagen.strict-validation")
vmArg("-Dfabric-api.datagen.modid=frozenlib_testmod")
ideConfigGenerated(true)
runDir = "build/test_datagen"
}
}
}
val includeModImplementation: Configuration by configurations.creating
val includeImplementation: Configuration by configurations.creating
configurations {
include {
extendsFrom(includeImplementation)
extendsFrom(includeModImplementation)
}
implementation {
extendsFrom(includeImplementation)
}
modImplementation {
extendsFrom(includeModImplementation)
}
}
val api by sourceSets.registering {
java {
compileClasspath += sourceSets.main.get().compileClasspath
}
}
val relocModApi: Configuration by configurations.creating {
configurations.modApi.get().extendsFrom(this)
}
sourceSets {
main {
java {
compileClasspath += api.get().output
runtimeClasspath += api.get().output
}
}
}
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
maven {
url = uri("https://jitpack.io")
}
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
content {
includeGroup("maven.modrinth")
}
}
maven {
url = uri("https://maven.terraformersmc.com")
content {
includeGroup("com.terraformersmc")
}
}
maven {
setUrl("https://maven.shedaniel.me/")
}
maven {
setUrl("https://maven.minecraftforge.net")
}
maven {
setUrl("https://maven.parchmentmc.org")
}
maven {
name = "Quilt"
setUrl("https://maven.quiltmc.org/repository/release")
}
flatDir {
dirs("libs")
}
mavenCentral()
}
dependencies {
// To change the versions see the gradle.properties file
minecraft("com.mojang:minecraft:$minecraft_version")
mappings(loom.layered {
// please annoy treetrain if this doesn't work
mappings("org.quiltmc:quilt-mappings:$quilt_mappings:intermediary-v2")
// parchment("org.parchmentmc.data:parchment-$parchment_mappings@zip")
officialMojangMappings {
nameSyntheticMembers = false
}
})
modImplementation("net.fabricmc:fabric-loader:$loader_version")
testImplementation("net.fabricmc:fabric-loader-junit:$loader_version")
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabric_api_version")
// Fabric Language Kotlin. Required to use the Kotlin language.
modImplementation("net.fabricmc:fabric-language-kotlin:$fabric_kotlin_version")
// Mod Menu
modApi("com.terraformersmc:modmenu:${modmenu_version}")
// Cloth Config
modCompileOnlyApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") {
exclude(group = "net.fabricmc.fabric-api")
exclude(group = "com.terraformersmc")
}
// TerraBlender
modCompileOnlyApi("com.github.glitchfiend:TerraBlender-fabric:${terrablender_version}")
// Toml
modApi("com.moandjiezana.toml:toml4j:$toml4j_version")//?.let { include(it) }
// Jankson
relocModApi("com.github.Treetrain1:Jankson:mod-SNAPSHOT")
// ExJson
//relocModApi("org.exjson:xjs-data:$xjs_data_version")
relocModApi("com.github.Treetrain1:xjs-data:infinity-compat-SNAPSHOT")
relocModApi("org.exjson:xjs-compat:$xjs_compat_version")
relocModApi("com.personthecat:fresult:$fresult_version")
compileOnly("org.projectlombok:lombok:1.18.34")?.let { annotationProcessor(it) }
"testmodImplementation"(sourceSets.main.get().output)
}
tasks {
processResources {
val properties = HashMap<String, Any>()
properties["version"] = project.version
properties["minecraft_version"] = "~1.21-"//minecraft_version
properties["fabric_loader_version"] = ">=$min_loader_version"
properties["fabric_api_version"] = ">=$fabric_api_version"
properties["fabric_kotlin_version"] = fabric_kotlin_version
properties.forEach { (a, b) -> inputs.property(a, b) }
filesMatching("fabric.mod.json") {
expand(properties)
}
}
license {
if (licenseChecks) {
rule(file("codeformat/QUILT_MODIFIED_HEADER"))
rule(file("codeformat/HEADER"))
include("**//*.java")
include("**//*.kt")
}
}
test {
useJUnitPlatform()
}
shadowJar {
configurations = listOf(relocModApi)
isEnableRelocation = true
relocationPrefix = "net.frozenblock.lib.shadow"
dependencies {
exclude {
it.moduleGroup.contains("fabric")
}
}
//relocate("blue.endless.jankson", "net.frozenblock.lib.config.api.jankson")
}
register("javadocJar", Jar::class) {
dependsOn(javadoc)
archiveClassifier = "javadoc"
from(javadoc.get().destinationDir)
}
register("sourcesJar", Jar::class) {
dependsOn(classes)
archiveClassifier = "sources"
from(sourceSets.main.get().allSource)
}
remapJar {
dependsOn(shadowJar)
input = shadowJar.get().archiveFile
}
withType(JavaCompile::class) {
options.encoding = "UTF-8"
options.release = 21
options.isFork = true
options.isIncremental = true
}
withType(KotlinCompile::class) {
compilerOptions {
jvmTarget = JvmTarget.JVM_21
}
}
withType(Test::class) {
maxParallelForks = Runtime.getRuntime().availableProcessors().div(2)
}
}
val build: Task by tasks
val applyLicenses: Task by tasks
val test: Task by tasks
val runClient: Task by tasks
val remapJar: Task by tasks
val sourcesJar: Task by tasks
val javadocJar: Task by tasks
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
// 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()
}
tasks {
jar {
from("LICENSE") {
rename { "${it}_${base.archivesName.get()}" }
}
}
}
artifacts {
archives(sourcesJar)
archives(javadocJar)
}
fun getModVersion(): String {
var version = "$mod_version-mc$minecraft_version"
if (release != null && !release) {
version += "-unstable"
}
return version
}
val dev by configurations.creating {
isCanBeResolved = true // maybe do false? idk?
isCanBeConsumed = true
}
tasks {
artifacts {
archives(remapJar)
archives(sourcesJar)
add("dev", jar)
}
}
val env: MutableMap<String, String> = System.getenv()
publishing {
val mavenUrl = env["MAVEN_URL"]
val mavenUsername = env["MAVEN_USERNAME"]
val mavenPassword = env["MAVEN_PASSWORD"]
//val release = mavenUrl?.contains("release")
val snapshot = mavenUrl?.contains("snapshot")
val publishingValid = rootProject == project && !mavenUrl.isNullOrEmpty() && !mavenUsername.isNullOrEmpty() && !mavenPassword.isNullOrEmpty()
val publishVersion = makeModrinthVersion(mod_version)
val snapshotPublishVersion = publishVersion + if (snapshot == true) "-SNAPSHOT" else ""
val publishGroup = rootProject.group.toString().trim(' ')
val hash = if (grgit.branch != null && grgit.branch.current() != null) grgit.branch.current().fullName else ""
publications {
var publish = true
try {
if (publishingValid) {
try {
val xml = ResourceGroovyMethods.getText(
URI.create("$mavenUrl/${publishGroup.replace('.', '/')}/$snapshotPublishVersion/$publishVersion.pom").toURL()
)
val metadata = XmlSlurper().parseText(xml)
if (metadata.getProperty("hash").equals(hash)) {
publish = false
}
} catch (ignored: FileNotFoundException) {
// No existing version was published, so we can publish
}
} else {
publish = false
}
} catch (e: Exception) {
publish = false
println("Unable to publish to maven. The maven server may be offline.")
}
if (publish) {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifact(javadocJar)
pom {
groupId = publishGroup
artifactId = rootProject.base.archivesName.get().lowercase()
version = snapshotPublishVersion
withXml {
asNode().appendNode("properties").appendNode("hash", hash)
}
}
}
}
}
repositories {
if (publishingValid) {
maven {
url = uri(mavenUrl!!)
credentials {
username = mavenUsername
password = mavenPassword
}
}
} else {
mavenLocal()
}
}
}
extra {
val properties = Properties()
properties.load(FileInputStream(file("gradle/publishing.properties")))
properties.forEach { (a, b) ->
project.extra[a as String] = b as String
}
}
val modrinth_id: String by extra
val release_type: String by extra
val changelog_file: String by extra
val modrinth_version = makeModrinthVersion(mod_version)
val display_name = makeName(mod_version)
val changelog_text = getChangelog(file(changelog_file))
fun makeName(version: String): String {
return "$version (${minecraft_version})"
}
fun makeModrinthVersion(version: String): String {
return "$version-mc${minecraft_version}"
}
fun getChangelog(changelogFile: File): String {
val text = Files.readString(changelogFile.toPath())
val split = text.split("-----------------")
if (split.size != 2)
throw IllegalStateException("Malformed changelog")
return split[1].trim()
}
fun getBranch(): String {
val env = System.getenv()
var branch = env["GITHUB_REF"]
if (branch != null && branch != "") {
return branch.substring(branch.lastIndexOf("/") + 1)
}
if (grgit == null) {
return "unknown"
}
branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = modrinth_id
versionNumber = modrinth_version
versionName = display_name
versionType = release_type
changelog = changelog_text
uploadFile = remapJar
gameVersions = listOf(minecraft_version)
loaders = listOf("fabric")
/*
additionalFiles = listOf(
tasks.remapSourcesJar.get(),
javadocJar
)
*/
dependencies {
required.project("fabric-api")
optional.project("cloth-config")
}
}
val github by tasks.register("github") {
dependsOn(remapJar)
val env = System.getenv()
val token = env["GITHUB_TOKEN"]
val repoVar = env["GITHUB_REPOSITORY"]
onlyIf {
token != null && token != ""
}
doLast {
val github = GitHub.connectUsingOAuth(token)
val repository = github.getRepository(repoVar)
val releaseBuilder = GHReleaseBuilder(repository, makeModrinthVersion(mod_version))
releaseBuilder.name(makeName(mod_version))
releaseBuilder.body(changelog_text)
releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(release_type != "release")
val ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(tasks.remapJar.get().archiveFile.get().asFile, "application/java-archive")
ghRelease.uploadAsset(tasks.remapSourcesJar.get().archiveFile.get().asFile, "application/java-archive")
ghRelease.uploadAsset(javadocJar.outputs.files.singleFile, "application/java-archive")
}
}
val publishMod by tasks.register("publishMod") {
dependsOn(tasks.publish)
dependsOn(github)
dependsOn(tasks.modrinth)
}