-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
202 lines (170 loc) · 6.47 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
@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)
}
loom {
if (stonecutter.current.isActive) {
runConfigs.all {
ideConfigGenerated(true)
runDir("../../run")
}
}
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 yaclVersion = property("vers.deps.yacl").toString()
val flk: String = "${libs.versions.fabric.language.kotlin.orNull}${libs.versions.kotlin.orNull}"
val fapi: String by lazy { property("vers.deps.fapi").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")
} else {
"neoForge"("net.neoforged:neoforge:${property("vers.deps.fml")}")
modImplementation("dev.nyon:KotlinLangForge:1.1.0-k${libs.versions.kotlin.orNull}-$mcVersion+${loader.name.lowercase()}")
}
modCompileOnly("dev.isxander:yet-another-config-lib:$yaclVersion")
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 mixinsFile = property("mod.mixins").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 yaclVersion,
"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)
filesMatching(if (isFabric) "fabric.mod.json" else "META-INF/neoforge.mods.toml") { expand(props) }
exclude(if (!isFabric) "fabric.mod.json" else "META-INF/neoforge.mods.toml")
}
register("releaseMod") {
group = "publishing"
dependsOn("publishMods")
dependsOn("publish")
}
withType<JavaCompile> {
options.release = javaVersion.toInt()
}
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
if (isFabric) modLoaders.addAll("fabric", "quilt")
else modLoaders.add("neoforge")
modrinth {
projectId = "lg17V3i3"
accessToken = providers.environmentVariable("MODRINTH_API_KEY")
minecraftVersions.addAll(supportedMcVersions)
if (isFabric) {
requires { slug = "fabric-api" }
requires { slug = "fabric-language-kotlin" }
optional { slug = "modmenu" }
} else {
requires { slug = "kotlin-lang-forge" }
}
optional { slug = "yacl" }
}
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
}
}