generated from stonecutter-versioning/stonecutter-template-fabric
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
240 lines (207 loc) · 9.04 KB
/
build.gradle.kts
File metadata and controls
240 lines (207 loc) · 9.04 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
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
import com.vanniktech.maven.publish.DeploymentValidation
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import groovy.util.Node
import groovy.util.NodeList
plugins {
id("com.vanniktech.maven.publish") version "0.36.0"
id("fabric-loom")
id("me.modmuss50.mod-publish-plugin")
}
version = "${property("mod.version")}+${stonecutter.current.version}"
base.archivesName = property("mod.id") as String
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.nucleoid.xyz/") { name = "Nucleoid" }
}
/**
* Courtesy to jakobkmar for the hack to include transitive dependencies: https://gist.github.com/jakobkmar/3c7e68ff57957d647a37ed568e5068c7
*
* To be honest, I don't know why there is no official documentation on the FabricMC wiki to support this.
* And the way to use shadow to shade the library causes an issue with Fabric Loom (include all runtime artifacts), which I still haven't found any solution to this, nor any official tutorial about this.
* I find it difficult for any newcomer to transfer knowledge from Maven to Gradle with its nonsense syntax that is called "flexibility" and all the hacks that are likely came out of nowhere.
* Still, there is no "superior" build tool, just one that one developer finds themselves convenient using.
*/
val transitiveInclude: Configuration by configurations.creating
fun DependencyHandler.transitiveImpl(
notation: Any,
configure: (ExternalModuleDependency.() -> Unit)? = null
) {
val dep = implementation(notation)
if (dep is ExternalModuleDependency && configure != null) {
dep.configure()
}
transitiveInclude.dependencies.add(dep!!)
}
fun DependencyHandler.transitiveApi(
notation: Any,
configure: (ExternalModuleDependency.() -> Unit)? = null
) {
val dep = api(notation)
if (dep is ExternalModuleDependency && configure != null) {
dep.configure()
}
transitiveInclude.dependencies.add(dep!!)
}
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, property("deps.fabric_api") as String))
}
minecraft("com.mojang:minecraft:${stonecutter.current.version}")
mappings("net.fabricmc:yarn:${property("deps.yarn")}:v2")
modImplementation("net.fabricmc:fabric-loader:${property("deps.fabric_loader")}")
fapi("fabric-lifecycle-events-v1", "fabric-networking-api-v1", "fabric-command-api-v2")
modImplementation("me.lucko:fabric-permissions-api:${property("deps.permissions_api")}")
modApi(include("eu.pb4:placeholder-api:${property("deps.text_placeholder_api")}")!!)
implementation("io.github.miniplaceholders:miniplaceholders-api:${property("deps.mini_placeholders")}")
modImplementation("net.kyori:adventure-platform-fabric:${property("deps.adventure_fabric")}")
include(api("me.hsgamer:hscore-common:${property("deps.hscore")}")!!)
include(api("me.hsgamer:hscore-builder:${property("deps.hscore")}")!!)
transitiveApi("me.hsgamer:hscore-config-proxy:${property("deps.hscore")}")
transitiveApi("me.hsgamer:hscore-config-configurate:${property("deps.hscore")}")
transitiveApi("me.hsgamer:hscore-database-client-java:${property("deps.hscore")}")
transitiveApi("org.spongepowered:configurate-gson:${property("deps.configurate")}") {
exclude("com.google.code.gson") // Use Minecraft's gson
}
transitiveApi("me.hsgamer:topper-template-top-player-number:${property("deps.topper")}")
transitiveApi("me.hsgamer:topper-template-storage-supplier:${property("deps.topper")}")
transitiveApi("me.hsgamer:topper-storage-flat-converter:${property("deps.topper")}")
transitiveApi("me.hsgamer:topper-storage-flat-properties:${property("deps.topper")}")
transitiveApi("me.hsgamer:topper-storage-sql-converter:${property("deps.topper")}")
transitiveApi("me.hsgamer:topper-storage-sql-config:${property("deps.topper")}")
transitiveApi("me.hsgamer:topper-storage-sql-mysql:${property("deps.topper")}") {
exclude("com.mysql", "mysql-connector-j")
}
transitiveApi("me.hsgamer:topper-storage-sql-sqlite:${property("deps.topper")}") {
exclude("org.xerial", "sqlite-jdbc")
}
transitiveInclude.resolvedConfiguration.resolvedArtifacts.forEach {
include(it.moduleVersion.id.toString())
}
}
loom {
decompilerOptions.named("vineflower") {
options.put("mark-corresponding-synthetics", "1") // Adds names to lambdas - useful for mixins
}
runConfigs.all {
ideConfigGenerated(true)
vmArgs("-Dmixin.debug.export=true") // Exports transformed classes for debugging
runDir = "../../run" // Shares the run directory between versions
}
}
java {
val requiresJava21: Boolean = stonecutter.eval(stonecutter.current.version, ">=1.20.6")
val javaVersion: JavaVersion =
if (requiresJava21) JavaVersion.VERSION_21
else JavaVersion.VERSION_17
targetCompatibility = javaVersion
sourceCompatibility = javaVersion
}
tasks {
processResources {
inputs.property("id", project.property("mod.id"))
inputs.property("name", project.property("mod.name"))
inputs.property("version", project.property("mod.version"))
inputs.property("minecraft", project.property("mod.mc_dep"))
val props = mapOf(
"id" to project.property("mod.id"),
"name" to project.property("mod.name"),
"version" to project.property("mod.version"),
"minecraft" to project.property("mod.mc_dep")
)
filesMatching("fabric.mod.json") { expand(props) }
}
// Builds the version into a shared folder in `build/libs/${mod version}/`
register<Copy>("buildAndCollect") {
group = "build"
from(remapJar.map { it.archiveFile })
into(rootProject.layout.buildDirectory.file("libs/${project.property("mod.version")}"))
dependsOn("build")
}
}
publishMods {
file = tasks.remapJar.map { it.archiveFile.get() }
displayName = "${property("mod.version")} for FabricMC ${stonecutter.current.version}"
version = property("mod.version") as String
changelog = rootProject.file("CHANGELOG.md").readText()
type = STABLE
modLoaders.add("fabric")
dryRun = providers.environmentVariable("MODRINTH_TOKEN").getOrNull() == null
modrinth {
projectId = property("publish.modrinth") as String
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
property("mod.mc_targets").toString().split(" ").forEach { it ->
minecraftVersions.add(it)
}
requires {
slug = "fabric-api"
}
requires {
slug = "placeholder-api"
}
optional {
slug = "miniplaceholders"
}
optional {
slug = "luckperms"
}
}
}
mavenPublishing {
publishToMavenCentral(automaticRelease = true, validateDeployment = DeploymentValidation.VALIDATED)
if (gradle.startParameter.taskNames.contains("publishToMavenCentral")) {
signAllPublications()
}
configure(
JavaLibrary(
javadocJar = JavadocJar.Javadoc(),
sourcesJar = true,
)
)
coordinates("${property("mod.group")}", "${property("mod.id")}", "${property("mod.version")}+${stonecutter.current.version}")
pom {
name = "Topper Fabric"
description = "A FabricMC project to implement Topper"
url = "https://github.com/Topper-MC/Topper-fabric"
licenses {
license {
name = "MIT License"
url = "https://github.com/Topper-MC/Topper-fabric/blob/master/LICENSE"
}
}
developers {
developer {
name = "HSGamer"
email = "huynhqtienvtag@gmail.com"
url = "https://github.com/HSGamer"
}
}
issueManagement {
system = "github"
url = "https://github.com/Topper-MC/Topper-fabric/issues"
}
scm {
connection = "scm:git:https://github.com/Topper-MC/Topper-fabric.git"
developerConnection = "scm:git:git@github.com:Topper-MC/Topper-fabric.git"
url = "https://github.com/Topper-MC/Topper-fabric"
}
withXml {
var root = asNode()
var dependencies = root["dependencies"] as NodeList
dependencies.forEach { dependency -> root.remove(dependency as Node?) }
}
}
}