-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
284 lines (239 loc) · 8.99 KB
/
build.gradle.kts
File metadata and controls
284 lines (239 loc) · 8.99 KB
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
@file:OptIn(StonecutterExperimentalAPI::class)
import com.google.devtools.ksp.processing.parseBoolean
import dev.kikugie.stonecutter.StonecutterExperimentalAPI
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.api.fabricapi.FabricApiExtension
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.loom) apply false
alias(libs.plugins.loom.remap) apply false
alias(libs.plugins.publishing)
alias(libs.plugins.blossom)
alias(libs.plugins.ksp)
alias(libs.plugins.fletchingtable.fabric)
id("maven-publish")
}
class ModData {
val id = property("mod.id") as String
val name = property("mod.name") as String
val version = property("mod.version") as String
val group = property("mod.group") as String
val description = property("mod.description") as String
val source = property("mod.source") as String
val issues = property("mod.issues") as String
val license = property("mod.license") as String
val modrinth = property("mod.modrinth") as String
val curseforge = property("mod.curseforge") as String
val discord = property("mod.discord") as String
val obfuscated = parseBoolean(property("mod.obfuscated") as String)
val minecraftVersion = property("mod.minecraft_version") as String
val minecraftVersionRange = property("mod.minecraft_version_range") as String
}
class Dependencies {
val fabricLoaderVersion = property("deps.fabric_loader_version") as String?
val devAuthVersion = property("deps.devauth_version") as String?
// Versioned
val neoForgeVersion = property("deps.neoforge_version") as String?
val fabricApiVersion = property("deps.fabric_api_version") as String?
}
val mod = ModData()
val deps = Dependencies()
// Apply specific loom
if (mod.obfuscated) {
apply(plugin = "net.fabricmc.fabric-loom-remap")
} else {
apply(plugin = "net.fabricmc.fabric-loom")
}
class LoaderData {
val name = property("loader.platform") as String?
val isFabric = "fabric".equals(name, ignoreCase = true)
val isNeoForge = "neoforge".equals(name, ignoreCase = true)
}
val loader = LoaderData()
val versionString = "${mod.version}-${mod.minecraftVersion}_${loader.name}"
group = mod.group
base {
archivesName.set("${mod.id}-${versionString}")
}
stonecutter {
replacements.string {
direction = eval(current.version, ">=26.2")
replace(".setScreen", ".gui.setScreen")
}
replacements.string {
direction = eval(current.version, ">=26.2")
replace("minecraft.screen", "minecraft.gui.screen()")
}
replacements.string {
direction = eval(current.version, ">=1.21.11")
replace("ResourceLocation", "Identifier")
}
}
// loom {
extensions.configure<LoomGradleExtensionAPI> {
runConfigs.all {
ideConfigGenerated(stonecutter.current.isActive)
runDir = "../../run"
}
runConfigs.remove(runConfigs["server"]) // Removes server run configs
runs {
afterEvaluate {
configureEach {
property("devauth.enabled", "true")
property("devauth.account", "main")
}
}
}
}
fletchingTable {
lang.create("main") {
patterns.add("assets/${mod.id}/lang/**")
}
}
repositories {
mavenCentral()
mavenLocal()
maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") // DevAuth
maven("https://maven.parchmentmc.org") // Parchment
maven("https://maven.neoforged.net/releases") // NeoForge
maven("https://maven.terraformersmc.com/") // Mod Menu
}
val loom: LoomGradleExtensionAPI by extensions
val fabricApi: FabricApiExtension by extensions
val minecraft by configurations.existing
val include by configurations.existing
val modImplementation: NamedDomainObjectProvider<Configuration> =
configurations.named(if (mod.obfuscated) "modImplementation" else "implementation")
val modRuntimeOnly: NamedDomainObjectProvider<Configuration> =
configurations.named(if (mod.obfuscated) "modRuntimeOnly" else "runtimeOnly")
dependencies {
minecraft("com.mojang:minecraft:${mod.minecraftVersion}")
if (mod.obfuscated) {
val mappings by configurations.existing
@Suppress("UnstableApiUsage")
mappings(loom.layered {
officialMojangMappings()
optionalProp("deps.parchment_version") {
parchment("org.parchmentmc.data:parchment-${mod.minecraftVersion}:$it@zip")
}
})
}
modRuntimeOnly("me.djtheredstoner:DevAuth-${loader.name}:${deps.devAuthVersion}")
if (loader.isFabric) {
modImplementation("net.fabricmc:fabric-loader:${deps.fabricLoaderVersion}")!!
optionalProp("deps.modmenu_version") { prop ->
modImplementation("com.terraformersmc:modmenu:$prop") {
exclude(group="net.fabricmc.fabric-api")
}
}
} else if (loader.isNeoForge) {
// TODO: "neoForge"("net.neoforged:neoforge:${deps.neoForgeVersion}")
}
}
val modrinthId = findProperty("publish.modrinth")?.toString()?.takeIf { it.isNotBlank() }
val curseforgeId = findProperty("publish.curseforge")?.toString()?.takeIf { it.isNotBlank() }
// accessTokens should be placed in the user Gradle gradle.properties file
// for example, on Windows this would be "C:\Users\{user}\.gradle\gradle.properties"
// then add:
// modrinth.token=
// curseforge.token=
publishMods {
}
java {
val requiredJava = when {
stonecutter.eval(stonecutter.current.version, ">=26.1") -> JavaVersion.VERSION_25
stonecutter.eval(stonecutter.current.version, ">=1.20.5") -> JavaVersion.VERSION_21
stonecutter.eval(stonecutter.current.version, ">=1.18") -> JavaVersion.VERSION_17
stonecutter.eval(stonecutter.current.version, ">=1.17") -> JavaVersion.VERSION_16
else -> JavaVersion.VERSION_1_8
}
sourceCompatibility = requiredJava
targetCompatibility = requiredJava
if (!mod.obfuscated) {
withSourcesJar()
}
}
tasks {
processResources {
val props = buildMap {
put("id", mod.id)
put("name", mod.name)
put("version", mod.version)
put("description", mod.description)
put("source", mod.source)
put("issues", mod.issues)
put("license", mod.license)
put("modrinth", mod.modrinth)
put("curseforge", mod.curseforge)
put("discord", mod.discord)
if (loader.isFabric) {
put("fabric_api_version", deps.fabricApiVersion?.trim())
put("fabric_loader_version", deps.fabricLoaderVersion?.trim())
} else if (loader.isNeoForge) {
put("neoforge_version", deps.neoForgeVersion?.trim())
}
val minecraftVersionRange = if (mod.minecraftVersionRange.contains(' ')) {
val parts = mod.minecraftVersionRange.trim().split(' ')
">=" + parts.first() + ' ' + "<=" + parts.last()
} else {
mod.minecraftVersionRange
}
put("minecraft_version_range", minecraftVersionRange)
}
props.forEach(inputs::property)
filesMatching("**/lang/en_us.json") { // Defaults description to English translation
expand(props)
filteringCharset = "UTF-8"
}
if (loader.isFabric) {
filesMatching("fabric.mod.json") { expand(props) }
exclude(listOf("META-INF/neoforge.mods.toml"))
}
if (loader.isNeoForge) {
filesMatching("META-INF/neoforge.mods.toml") { expand(props) }
exclude(listOf("fabric.mod.json"))
}
}
register<Copy>("buildAndCollect") {
group = "build"
if (mod.obfuscated) {
val remapJar by existing(net.fabricmc.loom.task.RemapJarTask::class)
val remapSourcesJar by existing(net.fabricmc.loom.task.RemapSourcesJarTask::class)
from(remapJar, remapSourcesJar)
} else {
val sourcesJar by existing
from(jar, sourcesJar)
}
into(rootProject.layout.buildDirectory.file("libs/${mod.version}"))
dependsOn("build")
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = mod.id
group = project.group
version = versionString
from(components["java"])
}
}
repositories {}
}
val currentCommitHash: String by lazy {
Runtime.getRuntime()
.exec(arrayOf("git", "rev-parse", "--verify", "--short", "HEAD"), null, rootDir)
.inputStream.bufferedReader().readText().trim()
}
blossom {
replaceToken("@MODID@", mod.id)
replaceToken("@VERSION@", mod.version)
replaceToken("@COMMIT_HASH@", currentCommitHash)
}
if (stonecutter.current.isActive) {
rootProject.tasks.register("buildActive") {
group = "project"
dependsOn(tasks.named("build"))
}
}
fun <T> optionalProp(property: String, block: (String) -> T?): T? =
findProperty(property)?.toString()?.takeUnless { it.isBlank() }?.let(block)