generated from devOS-Sanity-Edition/fabric-nautical-template-kt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
216 lines (179 loc) · 5.77 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm") version "2.0.21"
`maven-publish`
java
alias(libs.plugins.grgit)
alias(libs.plugins.fabric.loom)
alias(libs.plugins.ktor)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.shadow) apply false
}
val shade: Configuration by configurations.creating { }
val archivesBaseName = "${project.property("archives_base_name").toString()}+mc${libs.versions.minecraft.get()}"
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: 15, 30-82
*
*/
val fatJar = tasks.register<ShadowJar>("fatJar") {
group = "exposer"
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://api.modrinth.com/maven")
maven("https://maven.terraformersmc.com/")
maven("https://maven.parchmentmc.org")
maven("https://mvn.devos.one/snapshots")
maven("https://maven.quiltmc.org/repository/release/")
}
//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")
// mappings("${libs.quilt.mappings.get()}:intermediary-v2") // if you wanna deal with it be my guest, im not - asoji
})
//Fabric
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
modImplementation(libs.fabric.language.kotlin)
//Mods
modImplementation(libs.bundles.dependencies)
modLocalRuntime(libs.bundles.dev.mods)
include(modImplementation("gay.asoji:fmw:1.0.0+build.8")!!) // just to avoid the basic long metadata calls
implementation(libs.bundles.ktor)
shade(libs.bundles.ktor)
}
// 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")
}
}
// TODO: Uncomment for a non template mod!
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"]
// }
// }
// }
}
application {
mainClass.set("one.devos.nautical.exposeplayers.ExposePlayersKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
fun getModVersion(): String {
val modVersion = project.property("mod_version")
val buildId = System.getenv("GITHUB_RUN_NUMBER")
// CI builds only
if (buildId != null) {
return "${modVersion}+build.${buildId}"
}
// 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 (grgitService.service.get().grgit.head() != null) {
var id = grgitService.service.get().grgit.head().abbreviatedId ?: "NO-COMMIT-HASH"
// Flag the build if the build tree is not clean
// (aka you have uncommitted changes)
if (!grgitService.service.get().grgit.status().isClean()) {
id += "-dirty"
}
// ex: 1.0.0+rev.91949fa or 1.0.0+rev.91949fa-dirty
return "${modVersion}+rev.${id}"
}
// No tracking information could be found about the build
return "${modVersion}+unknown"
}