-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
157 lines (125 loc) · 5.25 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import me.modmuss50.mpp.ReleaseType
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
import org.gradle.internal.extensions.stdlib.capitalized
plugins {
id("architectury-plugin") version "3.4-SNAPSHOT"
id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false
id("com.gradleup.shadow") version "9.0.0-beta2" apply false
id("me.modmuss50.mod-publish-plugin") version "0.8.1"
}
fun Project.hasProp(namespace: String, key: String) = hasProperty("$namespace.$key")
fun Project.prop(namespace: String, key: String) = property("$namespace.$key") as String
val versions = prop("platform", "versions").split(",")
architectury.minecraft = versions.last()
group = prop("mod", "group")
version = "${prop("mod", "version")}+mc${versions.last()}"
tasks {
// Create a new task `buildAll` that builds and copies all jars to a common output directory.
val buildAll by registering(Copy::class) {
group = "build"
val tasks = subprojects.filter { it.path != ":common" }.map { it.tasks.named("remapJar") }
dependsOn(tasks)
from(tasks)
into(layout.buildDirectory.dir("libs"))
}
// We call buildAll to make sure everything is built before publishing.
publishMods.get().dependsOn(buildAll)
}
subprojects {
apply(plugin = "architectury-plugin")
apply(plugin = "dev.architectury.loom")
group = rootProject.group
version = "${rootProject.version}-$name"
val base = extensions.getByType<BasePluginExtension>()
base.archivesName.set(rootProject.prop("mod", "name"))
configure<LoomGradleExtensionAPI> {
dependencies {
"minecraft"("com.mojang:minecraft:${versions.last()}")
// Patch Yarn to work properly with NeoForge.
@Suppress("UnstableApiUsage")
"mappings"(layered {
mappings("net.fabricmc:yarn:${prop("fabric", "yarnVersion")}:v2")
mappings("dev.architectury:yarn-mappings-patch-neoforge:${prop("neoforge", "yarnPatch")}")
})
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(21)
}
// Shadow `common` into all loader projects.
if (path != ":common") {
apply(plugin = "com.gradleup.shadow")
val shadowCommon by configurations.creating {
configurations.getByName("implementation").extendsFrom(this)
}
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("dev-shadow")
configurations = listOf(shadowCommon)
}
tasks.named<RemapJarTask>("remapJar") {
inputFile.set(tasks.named<ShadowJar>("shadowJar").flatMap { it.archiveFile })
dependsOn("shadowJar")
injectAccessWidener.set(true)
}
tasks.named<Jar>("jar") {
archiveClassifier.set("dev")
}
}
}
/// Find the changelog entry for the given version in `CHANGELOG.md`.
fun fetchChangelog(modVersion: String): String {
val regex = Regex("## ${Regex.escape(modVersion)}\\n+([\\S\\s]*?)(?:\$|\\n+##)")
val content = file("CHANGELOG.md").readText().replace("\r\n", "\n")
return regex.find(content)?.groupValues?.get(1) ?: "*No changelog.*"
}
publishMods {
val modVersion = prop("mod", "version")
changelog.set(fetchChangelog(modVersion))
type.set(when {
modVersion.contains("alpha") -> ReleaseType.ALPHA
modVersion.contains("beta") -> ReleaseType.BETA
else -> ReleaseType.STABLE
})
/// Generate some common options between Modrinth and CurseForge publishing.
fun platformOptions(platform: String) = publishOptions {
val project = project(":$platform")
val name = if (platform == "neoforge") "NeoForge" else platform.capitalized()
displayName.set("$modVersion - $name ${versions.last()}")
version.set(project.version.toString())
modLoaders.addAll(project.prop("platform", "loaders").split(","))
file.set(project.tasks.getByName<RemapJarTask>("remapJar").archiveFile)
}.get()
modrinth("modrinthFabric") {
projectId.set(prop("modrinth", "id"))
accessToken.set(providers.environmentVariable("MODRINTH_TOKEN"))
from(platformOptions("fabric"))
minecraftVersions.addAll(versions)
requires("fabric-api")
optional("cloth-config")
}
modrinth("modrinthNeoForge") {
projectId.set(prop("modrinth", "id"))
accessToken.set(providers.environmentVariable("MODRINTH_TOKEN"))
from(platformOptions("neoforge"))
minecraftVersions.addAll(versions)
optional("cloth-config")
}
curseforge("curseforgeFabric") {
projectId.set(prop("curseforge", "id"))
accessToken.set(providers.environmentVariable("CURSEFORGE_TOKEN"))
from(platformOptions("fabric"))
minecraftVersions.addAll(versions)
requires("fabric-api")
optional("cloth-config")
}
curseforge("curseforgeNeoForge") {
projectId.set(prop("curseforge", "id"))
accessToken.set(providers.environmentVariable("CURSEFORGE_TOKEN"))
from(platformOptions("neoforge"))
minecraftVersions.addAll(versions)
optional("cloth-config")
}
}