-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
371 lines (291 loc) · 10 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
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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
plugins {
java
id("architectury-plugin") version "3.4-SNAPSHOT"
id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
id("systems.manifold.manifold-gradle-plugin") version "0.0.2-alpha"
id("maven-publish")
id("me.modmuss50.mod-publish-plugin") version "0.6.3"
}
/**
* Borrowed from Distant Horizons
*/
fun writeBuildGradlePredefine(AvailableVersion: List<String>, versionIndex: Int) {
val sb = StringBuilder()
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n")
for ((index, s) in AvailableVersion.withIndex()) {
val versionString = s.replace(".", "_")
sb.append("MC_${versionString}=${index}\n")
ext.set("MC_${versionString}", index.toString())
if (versionIndex == index) {
sb.append("MC_VER=${index}\n")
ext.set("MC_VER", index.toString())
}
}
File(projectDir, "build.properties").writeText(sb.toString())
}
project.gradle.extra.properties.forEach { prop ->
ext.set(prop.key, prop.value)
}
writeBuildGradlePredefine(project.properties["availableVersions"] as List<String>, project.properties["versionIndex"] as Int)
// gradle.properties
val supportedModLoaders: String by project
val projectArchivesName: String by project
val projectGroup: String by project
val modId: String by project
val modVersion: String by project
val projectJavaVersion: String by project
val modName: String by project
val modDescription: String by project
val modAuthor: String by project
val minecraftVersion: String by project
val parchmentVersion: String by project
val parchmentMinecraftVersion: String by project
val pandalibVersion: String by project
val architecturyVersion: String by project
val manifoldVersion: String by project
val fabricCompatibleVersions: String by project
val forgeCompatibleVersions: String by project
val neoForgeCompatibleVersions: String by project
architectury.minecraft = minecraftVersion
allprojects {
apply(plugin = "java")
tasks { base.archivesName = projectArchivesName }
version = "${modVersion}-${minecraftVersion}"
group = projectGroup
}
subprojects {
val isMinecraftSubProject = findProject(":common") != project
val isFabric = findProject(":fabric") == project
val isForge = findProject(":forge") == project
val isNeoForge = findProject(":neoforge") == project
apply(plugin = "architectury-plugin")
apply(plugin = "dev.architectury.loom")
apply(plugin = "maven-publish")
apply(plugin = "com.github.johnrengelman.shadow")
tasks { base.archivesName = "${projectArchivesName}-${project.name}" }
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom")
loom.silentMojangMappingsLicense()
configurations {
create("common") {
isCanBeResolved = true
isCanBeConsumed = false
}
compileClasspath.get().extendsFrom(configurations["common"])
runtimeClasspath.get().extendsFrom(configurations["common"])
// Files in this configuration will be bundled into your mod using the Shadow plugin.
// Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files.
create("shadowBundle") {
isCanBeResolved = true
isCanBeConsumed = false
}
create("jarShadow")
implementation.get().extendsFrom(configurations["jarShadow"])
getByName("shadowBundle").extendsFrom(configurations["jarShadow"])
create("modShadow")
getByName("modImplementation").extendsFrom(configurations["modShadow"])
getByName("include").extendsFrom(configurations["modShadow"])
}
repositories {
mavenCentral()
mavenLocal()
maven("https://maven.parchmentmc.org")
maven("https://maven.fabricmc.net/")
maven("https://maven.minecraftforge.net/")
maven("https://maven.neoforged.net/releases/")
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}
}
filter {
includeGroup("maven.modrinth")
}
}
}
@Suppress("UnstableApiUsage")
dependencies {
"minecraft"("com.mojang:minecraft:${minecraftVersion}")
"mappings"(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${parchmentMinecraftVersion}:${parchmentVersion}@zip")
})
"modImplementation"("me.pandamods:pandalib-${project.name}:${pandalibVersion}")
if (isMinecraftSubProject) {
"modApi"("dev.architectury:architectury-${project.name}:${architecturyVersion}")
} else {
"modApi"("dev.architectury:architectury:${architecturyVersion}")
}
compileOnly("org.jetbrains:annotations:24.1.0")
annotationProcessor("systems.manifold:manifold-preprocessor:${manifoldVersion}")
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(JavaLanguageVersion.of(projectJavaVersion).asInt())
options.compilerArgs.add("-Xplugin:Manifold")
}
if (isMinecraftSubProject) {
tasks.withType<ShadowJar>().configureEach {
configurations = listOf(project.configurations.getByName("shadowBundle"))
archiveClassifier.set("dev-shadow")
exclude("architectury.common.json")
}
tasks.withType<RemapJarTask>().configureEach {
val shadowJar = tasks.getByName<ShadowJar>("shadowJar")
inputFile.set(shadowJar.archiveFile)
}
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(JavaLanguageVersion.of(projectJavaVersion).asInt())
options.compilerArgs.add("-Xplugin:Manifold")
}
tasks.processResources {
val properties = mapOf(
"minecraftVersion" to minecraftVersion,
"modId" to modId,
"modVersion" to modVersion,
"modName" to modName,
"modDescription" to modDescription,
"modAuthor" to modAuthor,
"fabricCompatibleVersions" to fabricCompatibleVersions,
"forgeCompatibleVersions" to forgeCompatibleVersions,
"neoForgeCompatibleVersions" to neoForgeCompatibleVersions
)
inputs.properties(properties)
filesMatching(listOf("META-INF/mods.toml", "META-INF/neoforge.mods.toml", "pack.mcmeta", "fabric.mod.json")) {
expand(properties)
}
}
tasks.jar {
manifest {
attributes(mapOf(
"Specification-Title" to modName,
"Specification-Vendor" to modAuthor,
"Specification-Version" to modVersion,
"Implementation-Title" to name,
"Implementation-Vendor" to modAuthor,
"Implementation-Version" to archiveVersion
))
}
}
java {
withSourcesJar()
}
// Maven Publishing
publishing {
publications {
create<MavenPublication>("mod") {
groupId = projectGroup
artifactId = "${projectArchivesName}-${project.name}"
version = project.version as String
from(components["java"])
}
}
repositories {
}
}
}
// Mod Publishing
val publishingDryRun: String by project
val publishingReleaseType: String by project
val publishingMinecraftVersion: String by project
val publishingLatestMinecraftVersion = properties["publishingLatestMinecraftVersion"]
val publishingCurseForgeProjectId: String by project
val publishingModrinthProjectId: String by project
val publishingGitHubRepo: String by project
var curseForgeAPIKey = providers.environmentVariable("CURSEFORGE_API_KEY")
var modrinthAPIKey = providers.environmentVariable("MODRINTH_API_KEY")
var githubAPIKey = providers.environmentVariable("GITHUB_API_KEY")
publishMods {
dryRun = publishingDryRun.toBoolean()
version = modVersion
changelog = rootProject.file("CHANGELOG.md").readText()
// Set the release type
type = when (publishingReleaseType.toInt()) {
2 -> ALPHA
1 -> BETA
else -> STABLE
}
val isRangedVersion = publishingLatestMinecraftVersion != null
val minecraftVersionStr = if (isRangedVersion) {
"${publishingMinecraftVersion}-${publishingLatestMinecraftVersion}"
} else {
publishingLatestMinecraftVersion
}
// Creates publish options for each supported mod loader
supportedModLoaders.toString().split(",").forEach {
val loaderName = it
val loaderDisplayName = when (it) {
"fabric" -> "Fabric"
"forge" -> "Forge"
"neoforge" -> "NeoForge"
else -> it
}
val remapJar = project(":" + loaderName).tasks.getByName<RemapJarTask>("remapJar")
curseforge("curseforge_${loaderName}") {
accessToken = curseForgeAPIKey
displayName = "[${loaderDisplayName} ${minecraftVersionStr}] v${modVersion}"
projectId = publishingCurseForgeProjectId
modLoaders.add(loaderName)
file = remapJar.archiveFile
if (isRangedVersion)
minecraftVersionRange {
start = publishingMinecraftVersion
end = publishingLatestMinecraftVersion as String
}
else
minecraftVersions.add(publishingMinecraftVersion)
javaVersions.add(JavaVersion.VERSION_21)
clientRequired = true
serverRequired = true
if (loaderName == "fabric")
requires("fabric-api")
requires("architectury-api")
requires("pandalib")
}
modrinth("modrinth_" + loaderName) {
accessToken = modrinthAPIKey
displayName = "[${loaderDisplayName} ${minecraftVersionStr}] v${modVersion}"
projectId = publishingModrinthProjectId
modLoaders.add(loaderName)
file = remapJar.archiveFile
if (isRangedVersion)
minecraftVersionRange {
start = publishingMinecraftVersion
end = publishingLatestMinecraftVersion as String
}
else
minecraftVersions.add(publishingMinecraftVersion)
if (loaderName == "fabric")
requires("fabric-api")
requires("architectury-api")
requires("pandalib")
}
}
var githubRepository = publishingGitHubRepo
var releaseType = when (publishingReleaseType.toInt()) {
2 -> "alpha"
1 -> "beta"
else -> "stable"
}
var githubTagName = "${releaseType}/${modVersion}-${minecraftVersionStr}"
github {
accessToken = githubAPIKey
repository = githubRepository
tagName = githubTagName
commitish = "main"
modLoaders.addAll(supportedModLoaders.trim().split(","))
val commonRemapJar = project(":common").tasks.getByName<RemapJarTask>("remapJar")
file = commonRemapJar.archiveFile
supportedModLoaders.toString().split(",").forEach {
val modRemapJar = project(":$it").tasks.getByName<RemapJarTask>("remapJar")
additionalFiles.from(modRemapJar.archiveFile)
}
}
}