-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
306 lines (258 loc) · 8.9 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
@file:Suppress("UnstableApiUsage")
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.gradle.DokkaTask
import java.net.URL
buildscript {
dependencies {
classpath("org.jetbrains.dokka:dokka-base:1.9.10")
}
}
plugins {
kotlin("jvm") version "2.0.0"
`maven-publish`
java
alias(libs.plugins.grgit)
alias(libs.plugins.fabric.loom)
alias(libs.plugins.dokka)
alias(libs.plugins.shadow) apply false
}
val shade: Configuration by configurations.creating { }
val archivesBaseName = project.property("archives_base_name").toString()
version = getModVersion()
group = project.property("maven_group")!!
/*
*
* Taken from Deftu's Gradle-Toolkit with permission, and have explicit permission from Deftu himself to be excluded from Deftu's Gradle-Toolkit's LGPLv3 license
*
* src: https://github.com/Deftu/Gradle-Toolkit/blob/main/src/main/kotlin/dev/deftu/gradle/tools/shadow.gradle.kts
*
* lines affected: 27, 42-96
*
*/
val fatJar = tasks.register<ShadowJar>("fatJar") {
group = "innerpastels"
description = "Builds a fat JAR with all dependencies shaded in"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations = listOf(shade)
archiveVersion.set(project.version.toString())
archiveClassifier.set("all")
val javaPlugin = project.extensions.getByType(JavaPluginExtension::class.java)
val jarTask = project.tasks.getByName("jar") as Jar
manifest.inheritFrom(jarTask.manifest)
val libsProvider = project.provider { listOf(jarTask.manifest.attributes["Class-Path"]) }
val files = project.objects.fileCollection().from(shade)
doFirst {
if (!files.isEmpty) {
val libs = libsProvider.get().toMutableList()
libs.addAll(files.map { it.name })
manifest.attributes(mapOf("Class-Path" to libs.filterNotNull().joinToString(" ")))
}
}
from(javaPlugin.sourceSets.getByName("main").output)
exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "module-info.class")
}
project.artifacts.add("shade", fatJar)
pluginManager.withPlugin("java") {
tasks["assemble"].dependsOn(fatJar)
}
tasks {
val shadowJar = findByName("shadowJar")
if (shadowJar != null) {
named("shadowJar") {
doFirst {
throw GradleException("Incorrect task! You're looking for fatJar.")
}
}
}
}
loom {
tasks {
fatJar {
archiveClassifier.set("dev")
}
remapJar {
inputFile.set(fatJar.get().archiveFile)
archiveClassifier.set("")
}
}
}
repositories {
mavenCentral()
maven("https://maven.parchmentmc.org")
maven("https://mvn.devos.one/snapshots")
maven { url = uri("https://api.modrinth.com/maven") }
}
//All dependencies and their versions are in ./gradle/libs.versions.toml
dependencies {
minecraft(libs.minecraft)
mappings(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.21:2024.07.28@zip")
})
//Fabric
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
modImplementation(libs.fabric.language.kotlin) // how did i not have this
modImplementation(libs.sodium)
include(implementation("com.moulberry:mixinconstraints:1.0.1")!!)
listOf(
"binding" to true,
"lwjgl3" to true,
"natives-windows" to false,
"natives-linux" to false,
"natives-macos" to false
).forEach { (module, bundled) ->
val version = "1.87.1"
api("io.github.spair:imgui-java-$module:$version") {
exclude(group = "org.lwjgl")
}
if (bundled) {
include("io.github.spair:imgui-java-$module:$version")
} else {
shade("io.github.spair:imgui-java-$module:$version")
}
}
include(modApi("gay.asoji:fmw:1.0.0+build.8")!!)
}
tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets {
named("main") {
moduleName.set("Inner Pastels")
moduleVersion.set(project.version.toString())
includes.from("Module.md")
sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(URL("http://github.com/devOS-Sanity-Edition/InnerPastels/tree/kt/1.21/main/" + "src/main/kotlin"))
remoteLineSuffix.set("#L")
}
}
}
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
// customAssets = listOf(file("my-image.png"))
// customStyleSheets = listOf(file("my-styles.css"))
footerMessage = "(c) 2024 devOS: Sanity Edition, Team Nautical, asoji"
separateInheritedMembers = true
// templatesDir = file("dokka/templates")
mergeImplicitExpectActualDeclarations = true
}
}
// Write the version to the fabric.mod.json
tasks.processResources {
inputs.property("version", project.version)
filesMatching("fabric.mod.json") {
expand(mutableMapOf("version" to project.version))
}
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(21)
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
tasks.jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}" }
}
}
// This will attempt to publish the mod to the devOS Maven, otherwise it will build the mod locally
// This is auto run by GitHub Actions
task("buildOrPublish") {
group = "build"
var mavenUser = System.getenv().get("MAVEN_USER")
if (!mavenUser.isNullOrEmpty()) {
dependsOn(tasks.getByName("publish"))
println("prepared for publish")
} else {
dependsOn(tasks.getByName("build"))
println("prepared for build")
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = project.property("maven_group").toString()
artifactId = project.property("archives_base_name").toString()
version = getModVersion()
from(components.get("java"))
}
}
repositories {
maven {
url = uri("https://mvn.devos.one/${System.getenv()["PUBLISH_SUFFIX"]}/")
credentials {
username = System.getenv()["MAVEN_USER"]
password = System.getenv()["MAVEN_PASS"]
}
}
}
}
loom {
runs {
create("datagen") {
client()
name("Data Generation")
vmArgs(
"-Dfabric-api.datagen",
"-Dfabric-api.datagen.output-dir=${file("src/main/generated")}",
"-Dfabric-api.datagen.modid=${project.extra["archives_base_name"] as String}"
)
runDir("build/datagen")
}
create("testModClient") {
client()
name("Test Mod Client")
source(sourceSets.getByName("test"))
runDir("run/test")
}
create("testModServer") {
server()
name("Test Mod Server")
source(sourceSets.getByName("test"))
runDir("run/test_server")
}
create("Gametest") {
server()
name("Test")
source(sourceSets.getByName("test"))
vmArgs("-Dfabric-api.gametest")
vmArgs("-Dfabric-api.gametest.report-file=${project.buildDir}/junit.xml")
runDir("run/gametest_server")
}
}
}
sourceSets {
main {
resources {
srcDirs("src/main/generated")
exclude("src/main/generated/.cache")
}
}
}
fun getModVersion(): String {
val modVersion = project.property("mod_version")
val buildId = System.getenv("GITHUB_RUN_NUMBER")
val branch = grgit.branch.current.name.replace("/", ".")
// If a git repo can't be found, grgit won't work, this non-null check exists so you don't run grgit stuff without a git repo
if (grgit != null) {
val head = grgit.head()
var id = head.abbreviatedId
// Flag the build if the build tree is not clean
// (aka you have uncommitted changes)
if (!grgit.status().isClean()) {
id += "-dirty"
if (buildId != null) {
id = id.replace("-dirty", "")
} else {
id += ""
}
}
// ex: 1.0.0+rev.91949fa or 1.0.0+rev.91949fa-dirty
return "${modVersion}+rev.${id}-branch.${branch}"
}
// No tracking information could be found about the build
return "${modVersion}+unknown"
}