generated from isXander/FabricModTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathbuild.gradle.kts
488 lines (407 loc) · 16 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
import dev.isxander.stonecutterconfigurator.isExperimental
plugins {
id("dev.isxander.modstitch.base")
id("me.modmuss50.mod-publish-plugin")
`maven-publish`
id("dev.kikugie.postprocess.j52j") version "2.1-beta.3"
}
// version stuff
val mcVersion = property("mcVersion")!!.toString()
val mcSemverVersion = stonecutter.current.version
// loader stuff
val isFabric = modstitch.isLoom
val isNeoforge = modstitch.isModDevGradleRegular
val isForge = modstitch.isModDevGradleLegacy
val isForgeLike = modstitch.isModDevGradle
val loader = when {
isFabric -> "fabric"
isNeoforge -> "neoforge"
isForge -> "forge"
else -> error("Unknown loader")
}
val versionWithoutMC = property("modVersion")!!.toString()
modstitch {
minecraftVersion = mcVersion
// ideally, we use 17 for everything to tell IDE about the language features that are available
// on the lowest common denominator: 17. However, Forge versions that use a java 21 MC version
// won't compile on Java 17, so we need to use 21 for those.
val mcIsJava21 = stonecutter.eval(mcSemverVersion, ">1.20.4")
javaTarget = if (mcIsJava21 && isForgeLike) 21 else 17
parchment {
prop("parchment.version") { mappingsVersion = it }
prop("parchment.minecraft") { minecraftVersion = it }
}
metadata {
fun prop(property: String, block: (String) -> Unit) {
prop(property, ifNull = {""}) { block(it) }
}
modId = "controlify"
modName = "Controlify"
modVersion = "$versionWithoutMC+${stonecutter.current.project}"
modGroup = "dev.isxander"
modLicense = "LGPL-3.0-or-later"
modAuthor = "isXander"
prop("modDescription") { modDescription = it }
prop("packFormat") { replacementProperties.put("pack_format", it) }
prop("githubProject") { replacementProperties.put("github", it) }
prop("meta.mcDep") { replacementProperties.put("mc", it) }
prop("meta.loaderDep") { replacementProperties.put("loaderVersion", it) }
prop("deps.fabricApi") { replacementProperties.put("fapi", it) }
}
loom {
prop("deps.fabricLoader", required = true) { fabricLoaderVersion = it }
configureLoom {
runConfigs.all {
ideConfigGenerated(false)
vmArg("-Dsodium.checks.issue2561=false")
}
}
}
moddevgradle {
enable {
prop("deps.neoForge") { neoForgeVersion = it }
prop("deps.forge") { forgeVersion = it }
}
defaultRuns()
configureNeoforge {
runs.all {
disableIdeRun()
}
}
}
/*
Dynamically add mixins based on this target's supported mods.
*/
mixin {
addMixinsToModManifest = true
configs.register("controlify")
if (isPropDefined("deps.iris")) configs.register("controlify-compat.iris")
if (isPropDefined("deps.sodium")) configs.register("controlify-compat.sodium")
if (isPropDefined("deps.reesesSodiumOptions")) configs.register("controlify-compat.reeses-sodium-options")
configs.register("controlify-compat.yacl")
if (isPropDefined("deps.simpleVoiceChat")) configs.register("controlify-compat.simple-voice-chat")
if (isFabric) configs.register("controlify-platform.fabric")
if (isNeoforge) configs.register("controlify-platform.neoforge")
}
}
/*
Prod run environment from loom!
MDG targets don't need this, they run with named namespace.
*/
val productionMods: Configuration by configurations.creating {
isTransitive = false
}
if (isFabric) {
@Suppress("UnstableApiUsage")
val runProdClient by tasks.registering(net.fabricmc.loom.task.prod.ClientProductionRunTask::class) {
group = "fabric"
mods.from(productionMods)
jvmArgs = listOf("-Dsodium.checks.issue2561=false")
outputs.upToDateWhen { false }
}
} else {
val runProdClient by tasks.registering {
group = "controlify/versioned"
dependsOn("runClient") // neoforge is prod always
}
}
createActiveTask(taskName = "runClient")
createActiveTask(taskName = "runProdClient")
/*
Setup test harness for the project.
*/
val testharness by sourceSets.registering {
compileClasspath += sourceSets.main.get().compileClasspath
runtimeClasspath += sourceSets.main.get().runtimeClasspath
}
modstitch.createProxyConfigurations(testharness.get())
/*
Setup stonecutter for the project.
*/
stonecutter {
consts(
"fabric" to modstitch.isLoom,
"neoforge" to modstitch.isModDevGradleRegular,
"forge" to modstitch.isModDevGradleLegacy,
"forgelike" to modstitch.isModDevGradle,
)
val sodiumSemver = findProperty("deps.sodiumSemver")?.toString() ?: "0.0.0"
dependencies(
"fapi" to (findProperty("deps.fabricApi")?.toString() ?: "0.0.0"),
"sodium" to sodiumSemver
)
// sodium repackaged in 0.6, this allows quick swapping imports
swaps["sodium-package"] = if (eval(sodiumSemver, ">=0.6"))
"net.caffeinemc.mods.sodium" else "me.jellysquid.mods.sodium"
}
dependencies {
fun Dependency?.jij() = this?.also(::modstitchJiJ)
fun Dependency?.productionMod() = this?.also { productionMods(it) }
prop("deps.mixinExtras") {
when {
isFabric -> modstitchImplementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:$it")!!).jij()
isNeoforge -> implementation("io.github.llamalad7:mixinextras-neoforge:$it").jij()
isForge -> implementation("io.github.llamalad7:mixinextras-forge:$it").jij()
else -> error("Unknown loader")
}
}
fun modDependency(
id: String,
artifactGetter: (String) -> String,
requiredByDependants: Boolean = false,
supportsRuntime: Boolean = true,
extra: (Boolean) -> Unit = {}
) {
prop("deps.$id") { modVersion ->
val noRuntime = prop("deps.$id.noRuntime") { it.toBoolean() } == true
require(noRuntime || supportsRuntime) { "No runtime is not supported for $id" }
val configuration = if (requiredByDependants) {
if (noRuntime) "modstitchModCompileOnlyApi" else "modstitchModApi"
} else {
if (noRuntime) "modstitchModCompileOnly" else "modstitchModImplementation"
}
artifactGetter(modVersion).let {
configuration(it)
if (!noRuntime) productionMods(it)
}
extra(!noRuntime)
}
}
if (isFabric) {
modDependency("fabricApi", { "net.fabricmc.fabric-api:fabric-api:$it" }, requiredByDependants = true)
// mod menu compat
modDependency("modMenu", { "com.terraformersmc:modmenu:$it" })
}
modstitchModApi("dev.isxander:yet-another-config-lib:${property("deps.yacl")}") {
// was including old fapi version that broke things at runtime
exclude(group = "net.fabricmc.fabric-api", module = "fabric-api")
exclude(group = "thedarkcolour")
}.productionMod()
// bindings for SDL3
modstitchApi("dev.isxander:libsdl4j:${property("deps.sdl3Target")}-${property("deps.sdl34jBuild")}")
.jij()
// steam deck bindings
modstitchApi("dev.isxander:steamdeck4j:${property("deps.steamdeck4j")}")
.jij()
// used to identify controller PID/VID when SDL is not available
modstitchApi("org.hid4java:hid4java:${property("deps.hid4java")}")
.jij()
// Already included by YetAnotherConfigLib, but we need it too, so let's define explicit dep
api("org.quiltmc.parsers:json:${property("deps.quiltparsers")}")
// sodium compat
modDependency("sodium", { "maven.modrinth:sodium:$it" })
// RSO compat
modDependency("reesesSodiumOptions", { "maven.modrinth:reeses-sodium-options:$it" })
// iris compat
modDependency("iris", { "maven.modrinth:iris:$it" }) { runtime ->
if (runtime) {
modstitchModLocalRuntime("org.anarres:jcpp:1.4.14")
modstitchModLocalRuntime("io.github.douira:glsl-transformer:2.0.0-pre13")
}
}
// immediately-fast compat
modDependency("immediatelyFast", { "maven.modrinth:immediatelyfast:$it" }) { runtime ->
if (runtime) {
modstitchModLocalRuntime("net.lenni0451:Reflect:1.1.0")
}
}
// simple-voice-chat compat
modDependency("simpleVoiceChat", { "maven.modrinth:simple-voice-chat:$it" })
// fancy menu compat
modDependency("fancyMenu", { "maven.modrinth:fancymenu:$it" }, supportsRuntime = false)
"testharnessImplementation"(sourceSets.main.get().output)
}
j52j {
prettyPrint = true
}
/*
START
Set up the configuration to put native hashes in the jar
*/
val offlineJar by tasks.registering(Jar::class) {
group = "controlify/versioned/internal"
// include the contents of the regular jar
val inputJar = modstitch.finalJarTask
from(zipTree(inputJar.flatMap { it.archiveFile }))
dependsOn(inputJar)
// set the classifier
archiveClassifier.set("offline")
}
tasks.assemble { dependsOn(offlineJar) }
class NativeTarget(
val classifier: String,
val fileExtension: String,
val jnaPrefix: String,
val fileName: String,
configuration: String,
) {
val configurationName = "offlineNative$configuration"
}
val nativeTargets = listOf(
NativeTarget(classifier = "linux-aarch64", fileExtension = "so", jnaPrefix = "linux-aarch64/", fileName = "libSDL3", configuration = "LinuxAarch64"),
NativeTarget(classifier = "linux-x86_64", fileExtension = "so", jnaPrefix = "linux-x86-64/", fileName = "libSDL3", configuration = "LinuxX86_64"),
NativeTarget(classifier = "macos-universal", fileExtension = "dylib", jnaPrefix = "darwin-aarch64/", fileName = "libSDL3", configuration = "MacArm"),
NativeTarget(classifier = "macos-universal", fileExtension = "dylib", jnaPrefix = "darwin-x86-64/", fileName = "libSDL3", configuration = "MacIntel"),
NativeTarget(classifier = "windows-x86", fileExtension = "dll", jnaPrefix = "win32-x86/", fileName = "SDL3", configuration = "WinX86"),
NativeTarget(classifier = "windows-x86_64", fileExtension = "dll", jnaPrefix = "win32-x86-64/", fileName = "SDL3", configuration = "WinX86_64"),
)
val nativeHashConfiguration = configurations.create("nativeHashes")
nativeTargets.forEach { target ->
val nativesConfiguration = configurations.create(target.configurationName)
dependencies {
nativesConfiguration("dev.isxander:libsdl4j-natives:${property("deps.sdl3Target")}:${target.classifier}@${target.fileExtension}")
nativeHashConfiguration("dev.isxander:libsdl4j-natives:${property("deps.sdl3Target")}:${target.classifier}@${target.fileExtension}.md5")
}
offlineJar {
from(nativesConfiguration) {
into(target.jnaPrefix)
rename { "${target.fileName}.${target.fileExtension}" }
}
}
}
tasks.jar {
from(nativeHashConfiguration) {
into("sdl3-hashes/")
}
}
/*
END
Set up the configuration to put native hashes in the jar
*/
tasks.generateModMetadata {
eachFile {
// don't include photoshop files for the textures for development
if (name.endsWith(".psd")) {
exclude()
}
}
}
val releaseModVersion by tasks.registering {
group = "controlify/versioned"
dependsOn("publishMods")
if (!project.publishMods.dryRun.get()) {
dependsOn("publish")
}
}
createActiveTask(releaseModVersion)
val finalJarTasks = listOf(
offlineJar,
modstitch.finalJarTask,
)
val buildAndCollect by tasks.registering(Copy::class) {
group = "controlify/versioned"
finalJarTasks.forEach { jar ->
dependsOn(jar)
from(jar.flatMap { it.archiveFile })
}
into(rootProject.layout.buildDirectory.dir("finalJars"))
}
createActiveTask(buildAndCollect)
publishMods {
from(rootProject.publishMods)
dryRun = rootProject.publishMods.dryRun
file = modstitch.finalJarTask.flatMap { it.archiveFile }
additionalFiles.setFrom(offlineJar.map { it.archiveFile })
displayName = "$versionWithoutMC for $loader $mcVersion"
modLoaders.add(loader)
fun versionList(prop: String) = findProperty(prop)?.toString()
?.split(',')
?.map { it.trim() }
?: emptyList()
// modrinth and curseforge use different formats for snapshots. this can be expressed globally
val stableMCVersions = versionList("pub.stableMC")
val modrinthId: String by project
if (modrinthId.isNotBlank() && hasProperty("modrinth.token") && !isExperimental) {
modrinth {
projectId.set(modrinthId)
accessToken.set(findProperty("modrinth.token")?.toString())
minecraftVersions.addAll(stableMCVersions)
minecraftVersions.addAll(versionList("pub.modrinthMC"))
announcementTitle = "Download $mcVersion for ${loader.replaceFirstChar { it.uppercase() }} from Modrinth"
requires { slug.set("yacl") }
if (isFabric) {
requires { slug.set("fabric-api") }
optional { slug.set("modmenu") }
}
}
}
val curseforgeId: String by project
if (curseforgeId.isNotBlank() && hasProperty("curseforge.token") && !isExperimental) {
curseforge {
projectId = curseforgeId
projectSlug = findProperty("curseforgeSlug")!!.toString()
accessToken = findProperty("curseforge.token")?.toString()
minecraftVersions.addAll(stableMCVersions)
minecraftVersions.addAll(versionList("pub.curseMC"))
announcementTitle = "Download $mcVersion for ${loader.replaceFirstChar { it.uppercase() }} from CurseForge"
requires { slug.set("yacl") }
if (isFabric) {
requires { slug.set("fabric-api") }
optional { slug.set("modmenu") }
}
}
}
val githubProject: String by project
if (githubProject.isNotBlank() && hasProperty("github.token") && !isExperimental) {
github {
accessToken = findProperty("github.token")?.toString()
// will upload files to this parent task
parent(rootProject.tasks.named("publishGithub"))
}
}
}
publishing {
publications {
create<MavenPublication>("mod") {
from(components["java"])
artifactId = "controlify"
groupId = "dev.isxander"
}
}
repositories {
val username = prop("XANDER_MAVEN_USER") { it }
val password = prop("XANDER_MAVEN_PASS") { it }
if (username != null && password != null) {
maven(url = "https://maven.isxander.dev/releases") {
name = "XanderReleases"
credentials {
this.username = username
this.password = password
}
}
} else {
logger.warn("Xander Maven credentials not satisfied.")
}
}
}
fun <T> prop(property: String, required: Boolean = false, ifNull: () -> String? = { null }, block: (String) -> T?): T? {
return ((System.getenv(property) ?: findProperty(property)?.toString())
?.takeUnless { it.isBlank() }
?: ifNull())
.let { if (required && it == null) error("Property $property is required") else it }
?.let(block)
}
fun isPropDefined(property: String): Boolean {
return prop(property) { true } == true
}
fun createActiveTask(
taskProvider: TaskProvider<*>? = null,
taskName: String? = null,
internal: Boolean = false
): String {
val taskExists = taskProvider != null || taskName!! in tasks.names
val task = taskProvider ?: taskName?.takeIf { taskExists }?.let { tasks.named(it) }
val taskName = when {
taskProvider != null -> taskProvider.name
taskName != null -> taskName
else -> error("Either taskProvider or taskName must be provided")
}
val activeTaskName = "${taskName}Active"
if (stonecutter.current.isActive) {
rootProject.tasks.register(activeTaskName) {
group = "controlify${if (internal) "/versioned" else ""}"
task?.let { dependsOn(it) }
}
}
return activeTaskName
}