-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
220 lines (189 loc) · 7.26 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
@file:Suppress("SpellCheckingInspection", "UnstableApiUsage", "RedundantNullableReturnType")
import net.fabricmc.loom.util.ModPlatform
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.architectury.loom)
alias(libs.plugins.mod.publish)
`maven-publish`
}
val loader = loom.platform.get()
val isFabric = loader == ModPlatform.FABRIC
val beta: Int = property("mod.beta").toString().toInt()
val majorVersion: String = property("mod.major-version").toString()
val mcVersion = property("vers.mcVersion").toString() // Pattern is '1.0.0-beta1-1.20.6-pre.2+fabric'
version = "$majorVersion${if (beta != 0) "-beta$beta" else ""}-$mcVersion+${loader.name.lowercase()}"
group = property("mod.group").toString()
val githubRepo = property("mod.repo").toString()
base {
archivesName.set(rootProject.name)
}
val mixinsFile = property("mod.mixins").toString()
loom {
if (stonecutter.current.isActive) {
runConfigs.all {
ideConfigGenerated(true)
runDir("../../run")
}
}
if (loader == ModPlatform.FORGE) forge {
mixinConfigs(mixinsFile)
}
mixin { useLegacyMixinAp = false }
silentMojangMappingsLicense()
}
repositories {
mavenCentral()
maven("https://maven.terraformersmc.com")
maven("https://maven.quiltmc.org/repository/release/")
maven("https://repo.nyon.dev/releases")
maven("https://maven.isxander.dev/releases")
maven("https://thedarkcolour.github.io/KotlinForForge/")
maven("https://maven.neoforged.net/releases/")
}
val flk: String = "${libs.versions.fabric.language.kotlin.orNull}${libs.versions.kotlin.orNull}"
val fapi: String by lazy { property("vers.deps.fapi").toString() }
val yacl: String by lazy { property("vers.deps.yacl").toString() }
val modmenu: String by lazy { property("vers.deps.modMenu").toString() }
dependencies {
minecraft("com.mojang:minecraft:$mcVersion")
mappings(loom.layered {
val quiltMappings: String = property("vers.deps.quiltmappings").toString()
if (quiltMappings.isNotEmpty()) mappings("org.quiltmc:quilt-mappings:$quiltMappings:intermediary-v2")
officialMojangMappings()
})
implementation(libs.vineflower)
if (isFabric) {
implementation(libs.fabric.loader)
modImplementation("net.fabricmc.fabric-api:fabric-api:$fapi")
modImplementation("net.fabricmc:fabric-language-kotlin:$flk")
modImplementation("com.terraformersmc:modmenu:$modmenu")
modCompileOnly("dev.isxander:yet-another-config-lib:$yacl")
} else {
if (loader == ModPlatform.FORGE) {
"forge"("net.minecraftforge:forge:$mcVersion-${property("vers.deps.fml")}")
compileOnly(libs.mixinextras.common)
annotationProcessor(libs.mixinextras.common)
include(libs.mixinextras.forge)
implementation(libs.mixinextras.forge)
} else
"neoForge"("net.neoforged:neoforge:${property("vers.deps.fml")}")
modImplementation("dev.nyon:KotlinLangForge:1.0.3-k${libs.versions.kotlin.orNull}-$mcVersion+${loader.name.lowercase()}")
}
modImplementation(libs.konfig)
include(libs.konfig)
}
val javaVersion = if (stonecutter.eval(mcVersion, ">=1.20.6")) 21 else 17
val modId = property("mod.id").toString()
val modName = property("mod.name").toString()
val modDescription = property("mod.description").toString()
val mcVersionRange = property("vers.mcVersionRange").toString()
val icon = property("mod.icon").toString()
val slug = property("mod.slug").toString()
tasks {
processResources {
val props: Map<String, String?> = mapOf(
"id" to modId,
"name" to modName,
"description" to modDescription,
"version" to project.version.toString(),
"github" to githubRepo,
"mc" to mcVersionRange,
"flk" to if (!isFabric) null else flk,
"fapi" to if (!isFabric) null else fapi,
"yacl" to if (!isFabric) null else yacl,
"modmenu" to if (!isFabric) null else modmenu,
"repo" to githubRepo,
"icon" to icon,
"mixins" to mixinsFile,
"slug" to slug
).filterNot { it.value == null }
props.forEach(inputs::property)
if (isFabric) {
filesMatching("fabric.mod.json") { expand(props) }
exclude(listOf("META-INF/mods.toml", "META-INF/neoforge.mods.toml", "pack.mcmeta"))
} else {
filesMatching(listOf("META-INF/mods.toml", "META-INF/neoforge.mods.toml")) { expand(props) }
exclude("fabric.mod.json")
}
}
register("releaseMod") {
group = "publishing"
dependsOn("publishMods")
dependsOn("publish")
}
withType<JavaCompile> {
options.release = javaVersion
}
withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.fromTarget(javaVersion.toString())
}
}
}
val changelogText = buildString {
append("# v${project.version}\n")
if (beta != 0) appendLine("### As this is still a beta version, this version can contain bugs. Feel free to report ANY misbehaviours and errors!")
rootDir.resolve("changelog.md").readText().also(::append)
}
val supportedMcVersions: List<String> =
property("vers.supportedMcVersions")!!.toString().split(',').map(String::trim).filter(String::isNotEmpty)
publishMods {
displayName = "v${project.version}"
file = tasks.remapJar.get().archiveFile
changelog = changelogText
type = if (beta != 0) BETA else STABLE
when (loader) {
ModPlatform.FABRIC -> modLoaders.addAll("fabric", "quilt")
ModPlatform.FORGE -> modLoaders.addAll("forge")
ModPlatform.NEOFORGE -> modLoaders.addAll("neoforge")
else -> {}
}
modrinth {
projectId = "wTfH1dkt"
accessToken = providers.environmentVariable("MODRINTH_API_KEY")
minecraftVersions.addAll(supportedMcVersions)
if (isFabric) {
requires { slug = "fabric-api" }
requires { slug = "fabric-language-kotlin" }
optional { slug = "modmenu" }
if (stonecutter.compare(mcVersion, "1.20.1") >= 0) optional { slug = "yacl" }
} else {
requires { slug = "kotlin-lang-forge" }
}
}
github {
repository = githubRepo
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = property("mod.main-branch").toString()
}
}
publishing {
repositories {
maven {
name = "nyon"
url = uri("https://repo.nyon.dev/releases")
credentials {
username = providers.environmentVariable("NYON_USERNAME").orNull
password = providers.environmentVariable("NYON_PASSWORD").orNull
}
}
}
publications {
create<MavenPublication>("maven") {
groupId = "dev.nyon"
artifactId = modName
version = project.version.toString()
from(components["java"])
}
}
}
java {
withSourcesJar()
javaVersion.toInt().let { JavaVersion.values()[it - 1] }.let {
sourceCompatibility = it
targetCompatibility = it
}
}