-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.fabric.gradle.kts
More file actions
147 lines (124 loc) · 5.46 KB
/
Copy pathbuild.fabric.gradle.kts
File metadata and controls
147 lines (124 loc) · 5.46 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
plugins {
// This plugin applies the correct loom variant based on the Minecraft version
id("dev.kikugie.loom-back-compat")
id("me.modmuss50.mod-publish-plugin") version "2.0.1"
}
// DO NOT set group = ...!
version = "${property("mod.version")}+${sc.current.version}"
base.archivesName = "${property("mod.id") as String}-fabric"
val requiredJava: JavaVersion = when {
sc.current.parsed >= "26.1" -> JavaVersion.VERSION_25
sc.current.parsed >= "1.20.5" -> JavaVersion.VERSION_21
sc.current.parsed >= "1.18" -> JavaVersion.VERSION_17
sc.current.parsed >= "1.17" -> JavaVersion.VERSION_16
else -> JavaVersion.VERSION_1_8
}
// This can be used for publishing on Modrinth and Curseforge
val compatibleVersions: List<String> = sc.properties.rawOrNull("mod", "mc_releases")
?.asList().orEmpty().map { it.toString() }
repositories {
/**
* Restricts dependency search of the given [groups] to the [maven URL][url],
* improving the setup speed.
*/
fun strictMaven(url: String, alias: String, vararg groups: String) = exclusiveContent {
forRepository { maven(url) { name = alias } }
filter { groups.forEach(::includeGroup) }
}
strictMaven("https://www.cursemaven.com", "CurseForge", "curse.maven")
strictMaven("https://api.modrinth.com/maven", "Modrinth", "maven.modrinth")
maven("https://maven.terraformersmc.com/releases/")
maven("https://maven.shedaniel.me/")
}
dependencies {
/**
* Fetches only the required Fabric API modules to not waste time downloading all of them for each version.
* @see <a href="https://github.com/FabricMC/fabric">List of Fabric API modules</a>
*/
fun fapi(vararg modules: String) {
for (it in modules) modImplementation(fabricApi.module(it, sc.properties["deps.fabric_api"]))
}
minecraft("com.mojang:minecraft:${sc.current.version}")
// Applies Mojang Mappings on obfuscated versions
loomx.applyMojangMappings()
// Use `mod{dependency type}` even on 26.1+ - loom-back-compat converts them
modImplementation("net.fabricmc:fabric-loader:${property("deps.fabric_loader")}")
fapi("fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-content-registries-v0", "fabric-registry-sync-v0", "fabric-renderer-api-v1", "fabric-rendering-v1", "fabric-renderer-indigo")
include(implementation("org.yaml:snakeyaml:${property("deps.yaml")}")!!)
if (stonecutter.eval(stonecutter.current.version, "<=26.3")) {
//Mod menu
val modMenu = property("deps.modmenu") as String
modApi("com.terraformersmc:modmenu:$modMenu")
}
//Cloth config
val clothConfig = property("deps.cloth_config") as String
modApi("me.shedaniel.cloth:cloth-config-fabric:$clothConfig")
}
loom {
fabricModJsonPath = rootProject.file("src/main/resources/fabric.mod.json") // Useful for interface injection
decompilerOptions.named("vineflower") {
options.put("mark-corresponding-synthetics", "1") // Adds names to lambdas - useful for mixins
}
runConfigs.all {
preferGradleTask = true
generateRunConfig = true
runDirectory = rootProject.file("run") // Shares the run directory between versions
jvmArguments.add("-Dmixin.debug.export=true") // Exports transformed classes for debugging
}
}
java {
withSourcesJar()
targetCompatibility = requiredJava
sourceCompatibility = requiredJava
toolchain {
vendor = JvmVendorSpec.ADOPTIUM
languageVersion = JavaLanguageVersion.of(requiredJava.majorVersion)
}
}
tasks {
processResources {
fun MutableMap<String, String>.register(key: String, property: String) {
val value: String = sc.properties[property]
inputs.property(key, value)
set(key, value)
}
val props = buildMap {
register("id", "mod.id")
register("name", "mod.name")
register("version", "mod.version")
register("minecraft", "mod.mc_compat")
}
filesMatching("fabric.mod.json") { expand(props) }
val mixinJava = "JAVA_${requiredJava.majorVersion}"
filesMatching("*.mixins.json") { expand("java" to mixinJava) }
exclude("META-INF/neoforge.mods.toml")
}
register<Copy>("buildAndCollect") {
group = "build"
description = "Builds mod jars and copies results to `build/libs/{mod version}/`"
inputs.property("version", project.property("mod.version"))
// loomx.mod(Sources)Jar returns the jar task for the applied loom variant
from(loomx.modJar.flatMap { it.archiveFile }, loomx.modSourcesJar.flatMap { it.archiveFile })
into(rootProject.layout.buildDirectory.file("libs/${project.property("mod.version")}"))
}
}
publishMods {
val mrToken = providers.environmentVariable("MODRINTH_TOKEN")
val modVersion = "${project.property("mod.version")}+${stonecutter.current.version}"
type.set(BETA)
if (stonecutter.eval(stonecutter.current.version, "<=1.21.11")) {
file.set(tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar").flatMap { it.archiveFile })
}else {
file.set(tasks.jar.map { it.archiveFile.get() })
}
changelog.set(provider { rootProject.file("CHANGELOG.md").readText() })
modLoaders.add("fabric")
version.set(modVersion)
displayName.set(modVersion)
modrinth {
projectId = "rOrXjyPb"
accessToken = mrToken
requires("fabric-api")
minecraftVersions.add(stonecutter.current.version)
}
}