-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
414 lines (364 loc) · 15.3 KB
/
build.gradle.kts
File metadata and controls
414 lines (364 loc) · 15.3 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
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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import dev.architectury.plugin.ArchitectPluginExtension
import net.fabricmc.loom.LoomGradleExtension
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import dependencies.minecraft as MC
import org.apache.tools.ant.filters.StripJavaComments
plugins {
id("java")
id("architectury-plugin") version "3.4-SNAPSHOT"
id("io.github.null2264.architectury-loom") version "1.13-SNAPSHOT" apply false
id("com.gradleup.shadow") apply false
id("me.modmuss50.mod-publish-plugin") version "1.1.0"
}
val modVersion = System.getenv("VERSION") ?: project.properties["mod_version"] as? String ?: "0.0.0"
val loaderName = project.properties["null2264.platform"] as? String ?: ""
val isForge = loaderName.endsWith("forge")
val isNeo = loaderName.endsWith("neoforge")
val isFabric = loaderName.endsWith("fabric")
val _mcVer = project.properties["mcVer"] as? String ?: ""
val mcVersionStr = if (_mcVer.startsWith("1.")) _mcVer else "2.$_mcVer"
val (major, minor, patch, hotfix) = mcVersionStr
.split(".")
.toMutableList()
.apply { while (this.size < 4) this.add("") }
val mcHotfix: Int = hotfix.toIntOrNull() ?: 0
val mcVersion: Int = "${major}${minor.padStart(2, '0')}${patch.padStart(2, '0')}".toInt()
val versionRange = supportedVersionRange(mcVersion, loaderName)
fun setupPreprocessor() {
val buildProps = buildString {
append("# DON'T TOUCH THIS FILE, This is handled by the build script\n")
append("MC=${mcVersion}\n")
append("BUILD=${mcHotfix}\n")
if (isFabric) append("FABRIC=1\n")
if (isForge) append("FORGE=${if (!isNeo) "1" else "2"}\n")
}
project.file("build.properties").writeText(buildProps)
}
setupPreprocessor()
architectury {
minecraft = MC.versioned(mcVersion, mcHotfix)
}
allprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
ext["mcVersion"] = mcVersion
ext["mcVersionStr"] = mcVersionStr
ext["mcHotfix"] = mcHotfix
ext["loaderName"] = loaderName
ext["isFabric"] = isFabric
ext["isForge"] = isForge
ext["isNeo"] = isNeo
base.archivesName.set(rootProject.properties["archives_base_name"] as? String ?: "")
val buildNumber: String? = System.getenv("GITHUB_RUN_NUMBER")
version = buildString {
append(modVersion)
append("+")
append(mcVersionStr)
if (buildNumber != null) {
append("b")
append(buildNumber)
}
append("-")
append(rootProject.properties["version_stage"])
if (isFabric)
append("-fabric")
else
append(if (isNeo) "-neoforge" else "-forge")
}
group = rootProject.properties["maven_group"] as String
repositories {
maven("https://jitpack.io")
maven("https://maven.fabricmc.net/")
maven("https://libraries.minecraft.net/")
maven {
url = uri("https://maven.blamejared.com/")
content {
includeGroup("mezz.jei")
}
}
maven("https://maven.gegy.dev/releases/")
maven("https://maven.shedaniel.me/")
maven("https://maven.terraformersmc.com/")
maven("https://maven.jamieswhiteshirt.com/libs-release")
maven("https://maven.theillusivec4.top/")
maven("https://maven.neoforged.net/releases")
maven("https://raw.githubusercontent.com/Fuzss/modresources/main/maven/")
maven("https://maven.createmod.net")
maven("https://api.modrinth.com/maven/")
maven("https://cursemaven.com/")
mavenLocal()
maven("https://mvn.devos.one/snapshots/")
maven {
url = uri("https://maven.tterrag.com/")
content {
// Tell tterrag's maven to stfu, it spits out timeout instead of 404 for some reason
includeGroupByRegex("(com\\.)?tterrag")
}
}
}
tasks.withType<JavaCompile> {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
options.encoding = "UTF-8"
options.compilerArgs.add("-Xplugin:Manifold --no-bootstrap")
}
}
subprojects {
// NOTE: This here for when I finally split the API to its own module, hopefully on v6.0
val isApi = false; // APIs shouldn't contain anything Minecraft related
val isModModule = project == project(":cobblegen")
// Modules that contains MC-related stuff
val isMcModule = isModModule || project == project(":mclib")
apply(plugin = "java")
apply(plugin = "com.gradleup.shadow")
if (isModModule) {
// NOTE: This must be set before archloom is applied!
extra.set("loom.platform", loaderName)
}
if (isMcModule) {
apply(plugin = "architectury-plugin")
apply(plugin = "io.github.null2264.architectury-loom")
val arch = project.extensions["architectury"] as ArchitectPluginExtension
arch.apply {
if (isModModule)
loader(loaderName)
else
common(listOf(loaderName))
}
val loom = project.extensions["loom"] as LoomGradleExtension
loom.apply {
silentMojangMappingsLicense()
}
}
val manifoldVersion = project.properties["manifold_version"] as? String ?: ""
val shade: Configuration by configurations.creating {
configurations.implementation.get().extendsFrom(this)
}
val shadeInternal: Configuration by configurations.creating
val loaderProd = when {
isFabric -> "Fabric"
isNeo -> "NeoForge"
isForge -> "Forge"
else -> throw IllegalStateException("Unknown loader!")
}
// For internal libraries
val compileInternal: Configuration by configurations.creating {
configurations.compileClasspath.get().extendsFrom(this)
configurations.runtimeClasspath.get().extendsFrom(this)
if (isModModule) {
configurations["development$loaderProd"].extendsFrom(this)
}
}
val manifoldCompile: Configuration by configurations.creating {
configurations.compileOnly.get().extendsFrom(this)
configurations.annotationProcessor.get().extendsFrom(this)
configurations.testAnnotationProcessor.get().extendsFrom(this)
}
if (isModModule && !isFabric) {
configurations.named("forgeRuntimeLibrary").get().extendsFrom(shade)
}
val loom by lazy {
if (!isMcModule) {
throw IllegalStateException("Loom only available for MC modules")
}
project.the<LoomGradleExtensionAPI>()
}
dependencies {
if (isMcModule) {
val minecraft by configurations
val mappings by configurations
minecraft(MC.versioned(mcVersion, mcHotfix))
mappings(loom.officialMojangMappings())
}
shade("blue.endless:jankson:${project.properties["jankson_version"]}")
shade("systems.manifold:manifold-ext-rt:${manifoldVersion}")
manifoldCompile("systems.manifold:manifold-ext:${manifoldVersion}")
manifoldCompile("systems.manifold:manifold-preprocessor:${manifoldVersion}")
if (isModModule) {
compileOnly(project(":stubs"))
compileInternal(project(":mclib", configuration = "namedElements")) { isTransitive = false }
shadeInternal(project(":mclib", configuration = "transformProduction$loaderProd")) {
// Remove Junit test libraries
exclude(group = "org.junit.jupiter", module = "junit-jupiter")
exclude(group = "org.junit.jupiter", module = "junit-jupiter-engine")
exclude(group = "junit", module = "junit")
// Removed dependencies
isTransitive = false
}
if (mcVersion <= 11605) {
// slf4j is not included by MC in 1.16.5
shade("org.slf4j:slf4j-api:1.7.36")
shade("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
}
}
}
val shadowJar by tasks.getting(ShadowJar::class) {
isZip64 = true
relocate("blue.endless.jankson", "io.github.null2264.shadowed.jankson")
if (mcVersion <= 11605) {
relocate("org.slf4j", "io.github.null2264.shadowed.slf4j")
relocate("org.apache.logging", "io.github.null2264.shadowed.log4j")
}
relocate("manifold", "io.github.null2264.shadowed.manifold")
relocate("io.github.null2264.cobblegen.extensions", "io.github.null2264.shadowed.cobblegen.extensions")
if (isFabric) {
exclude("META-INF/mods.toml")
exclude("META-INF/neoforge.mods.toml")
} else if (isForge) {
exclude("fabric.mod.json")
exclude(if (isNeo && mcVersion >= 12006) "META-INF/mods.toml" else "META-INF/neoforge.mods.toml")
}
exclude("architectury.common.json")
configurations = listOf(shade, shadeInternal)
archiveClassifier.set("dev-shade")
mergeServiceFiles()
}
artifacts.add("archives", shadowJar)
val processResources by tasks.getting(ProcessResources::class) {
if (!isModModule) return@getting
val metadataVersion = "${modVersion}-${project.properties["version_stage"]}"
val metadataMCVersion = if (isForge) versionRange.mavenStyle() else versionRange.semverStyle()
val properties = mapOf(
"version" to metadataVersion,
"mcversion" to metadataMCVersion,
"forge" to (if (isNeo) "neoforge" else "forge"),
)
inputs.properties(properties)
filteringCharset = Charsets.UTF_8.name()
val metadataFilename =
if (isFabric) {
"fabric.mod.json"
} else {
if (isNeo && mcVersion >= 12006) "META-INF/neoforge.mods.toml" else "META-INF/mods.toml"
}
filesMatching(metadataFilename) {
filter<StripJavaComments>()
expand(properties)
}
filesMatching("cobblegen.mixins.json") {
filter<StripJavaComments>()
}
doLast {
// For some reason Mojang rename the structure directory on MC 1.21 to singular form
val structureDirName = if (mcVersion >= 12100) "structure" else "structures"
if (isFabric || mcVersion >= 12105) {
project.file("build/resources/main/data/cobblegen/gametest/${structureDirName}/").mkdirs()
project.file("build/resources/main/data/cobblegen/gametest/${structureDirName}/empty.snbt")
.writeStructureAsSnbt(generateStructure(false))
} else {
project.file("build/resources/main/data/cobblegen/${structureDirName}/").mkdirs()
project.file("build/resources/main/data/cobblegen/${structureDirName}/empty.nbt")
.writeStructureAsNbt(generateStructure(true))
}
project.file("build/resources/main/META-INF/mods.toml")
.processModsToml(mcVersion, if (!isForge) 0 else (if (isNeo) 2 else 1))
// We can't preprocess resources files with Manifold, so we'll construct the json files manually here instead.
project.file("build/resources/main/cobblegen.mixins.json").processMixinsJson(mcVersion, isFabric)
if (isFabric) project.file("build/resources/main/fabric.mod.json").processFabricModJson(mcVersion)
}
}
val targetJavaVersion = if (!isApi) {
if (mcVersion >= 12006) 21 else (if (mcVersion >= 11700) 17 else 8)
} else {
8 // APIs should always target Java 8
}
tasks.withType<JavaCompile> {
if (targetJavaVersion > 8) {
options.release = targetJavaVersion
}
}
java {
val javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() != javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
// 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()}" }
}
}
// In case I decided to split :cobblegen to multi-loader modules
// tasks.create<Copy>("copyCommonLoaderResources") {
// from(project(":common").file("src/main/resources/....")) {
// into(file(project.file("build/resources/main")))
// rename("...", "...")
// }
// }
}
//tasks.create("testMcVersions") {
// println(mcVersions(supportedVersionRange(11902, "fabric"))
// .map { if (it.isPreRelease) it.copy(preRelease = "Snapshot") else it }.distinct().map { it.toMojangString() })
//}
publishMods {
val mainProject = project(":cobblegen")
file.set(mainProject.file("build/libs/${rootProject.properties["archives_base_name"]}-${mainProject.version}.jar"))
val releaseVersions = mcVersions(versionRange, filters = listOf("release"))
displayName.set(
buildString {
append("[")
if (isFabric) {
append("FABRIC")
} else {
if (isNeo) append("NEOFORGE") else append("FORGE")
}
append(" MC")
append(releaseVersions[0])
if (releaseVersions.size > 1) append("+")
append("]")
append(" v")
append(modVersion)
append("-")
append(rootProject.properties["version_stage"])
if (mcVersion <= 11605) append(" (LITE)")
}
)
changelog.set(System.getenv("CHANGELOG") ?: "Please visit our [releases](https://github.com/null2264/CobbleGen/releases) for a changelog")
version.set(mainProject.version.toString())
if (isFabric) {
modLoaders.add("fabric")
modLoaders.add("quilt")
} else {
if (mcVersion <= 12002 && !isNeo) // No more LexForge, LexForge is too buggy
modLoaders.add("forge")
if (mcVersion == 12001 || isNeo)
modLoaders.add("neoforge")
}
type = when(rootProject.properties["version_stage"]) {
"ALPHA" -> ALPHA
"BETA" -> BETA
else -> STABLE
}
val cfToken = System.getenv("CURSEFORGE")
if (cfToken != null) {
curseforge {
accessToken = cfToken
projectId.set(rootProject.properties["curseforge_project"] as String)
// Because CF did it the lazy way and just group every snapshot as a single snapshot
minecraftVersions =
releaseVersions
.map { if (it.isPreRelease) it.copy(preRelease = "Snapshot") else it }
.distinct()
.map { it.toMojangString() }
embeds {
slug = "jankson"
}
}
}
val mrToken = System.getenv("MODRINTH")
if (mrToken != null) {
modrinth {
accessToken = mrToken
projectId.set(rootProject.properties["modrinth_project"] as String)
minecraftVersions =
releaseVersions.map { it.toMojangString() }
}
}
}