-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
284 lines (242 loc) · 10.5 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
284 lines (242 loc) · 10.5 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
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
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import org.gradle.api.attributes.Usage
plugins {
java
id("com.gradleup.shadow") version "9.3.1"
id("io.freefair.lombok") version "9.1.0"
id("io.papermc.hangar-publish-plugin") version "0.1.4"
id("io.sentry.jvm.gradle") version "5.12.2"
`maven-publish`
}
group = "de.keyle"
val buildType = project.findProperty("buildType")?.toString() ?: "local"
val minecraftVersion by extra("26.2")
val bukkitPackets by extra("v1_8_R3;v1_12_R1;v1_16_R3;v1_17_R1;v1_18_R1;v1_18_R2;v1_19_R2;v1_19_R3;v1_20_R1;v1_20_R2;v1_20_R3;v1_20_R4;v1_21_R1;v1_21_R2;v1_21_R3;v1_21_R4;v1_21_R5;v1_21_R6;v1_21_R7;v26_1_R1;v26_2_R1")
val specialVersions by extra("")
version = "3.14.3"
@Suppress("UNCHECKED_CAST")
val nmsModules: List<String> = gradle.extra["nmsModules"] as List<String>
// Shared repositories for all projects (root + subprojects)
allprojects {
repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
maven("https://repo.userderezzed.dev/releases")
maven("https://repo.userderezzed.dev/snapshots")
maven("https://repo.mypet-plugin.de/")
}
}
subprojects {
apply(plugin = "java-library")
apply(plugin = "io.freefair.lombok")
apply(plugin = "io.sentry.jvm.gradle")
repositories {
maven("https://mvn.lib.co.nz/spigot/")
maven("https://repo.md-5.net/content/groups/public/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://maven.enginehub.org/repo/")
maven("https://repo.md-5.net/content/repositories/public")
maven("https://jitpack.io")
}
tasks.named("processResources") { enabled = false }
tasks.named("test") { enabled = false }
tasks.named("compileTestJava") { enabled = false }
tasks.named("processTestResources") { enabled = false }
if (project.name != "api") {
plugins.withId("maven-publish") {
tasks.withType<PublishToMavenRepository>().configureEach { enabled = false }
tasks.withType<PublishToMavenLocal>().configureEach { enabled = false }
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(25))
}
}
}
val archivesBaseName = "MyPet"
val versionSuffix = when (buildType) {
"release" -> ""
"snapshot", "dev" -> "-SNAPSHOT"
else -> "-SNAPSHOT-local" // local builds
}
val fullVersion = "${project.version}$versionSuffix"
sourceSets {
main {
resources { srcDir("src/main/resources/") }
}
}
val downloadTranslations by tasks.register<Exec>("downloadTranslations") {
group = "resources"
description = "Downloads MyPet translations into build/resources/main/locale"
val targetDir = layout.buildDirectory.dir("resources/main/locale").get().asFile
outputs.dir(targetDir)
// Skip download if translations are less than 12 hours old
val maxAgeMillis = 12 * 60 * 60 * 1000L // 12 hours in milliseconds
onlyIf {
if (!targetDir.exists()) {
true
} else {
val ageMillis = System.currentTimeMillis() - targetDir.lastModified()
val shouldDownload = ageMillis > maxAgeMillis
if (!shouldDownload) {
logger.lifecycle("Skipping translation download - last updated ${ageMillis / (60 * 60 * 1000)} hours ago (max: 12 hours)")
}
shouldDownload
}
}
doFirst {
if (targetDir.exists()) targetDir.deleteRecursively()
targetDir.mkdirs()
}
commandLine(
"git", "clone", "--depth", "1", "--single-branch",
"https://github.com/MyPetORG/MyPet-Translations.git", targetDir
)
doLast {
// Clean up files we don't need in the final JAR
// Use direct File operations for configuration cache compatibility
File(targetDir, ".git").deleteRecursively()
File(targetDir, ".gitignore").delete()
File(targetDir, "README.md").delete()
File(targetDir, "exclude").deleteRecursively()
}
}
tasks.named<ProcessResources>("processResources") {
dependsOn(downloadTranslations)
duplicatesStrategy = DuplicatesStrategy.WARN
// Define filtering properties inline for configuration cache compatibility
val filteringProps = mapOf(
"buildNumber" to (providers.gradleProperty("BUILD_NUMBER").orNull ?: ""),
"gitCommit" to (System.getenv("GIT_COMMIT") ?: ""),
"minecraft" to mapOf("version" to minecraftVersion),
"bukkit" to mapOf("packets" to bukkitPackets),
"special" to mapOf("versions" to specialVersions),
"mypetVersion" to version,
"timestamp" to DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm").format(LocalDateTime.now()),
)
filesMatching("*.yml") { expand(filteringProps) }
}
fun Manifest.attributesForMyPet() = attributes(
mapOf(
"Class-Path" to "MyPet/rhino.jar MyPet/rhino-1.7.9.jar MyPet/rhino-1.7.10.jar MyPet/rhino-1.7.15.jar ../MyPet/rhino.jar ../MyPet/rhino-1.7.9.jar ../MyPet/rhino-1.7.10.jar ../MyPet/rhino-1.7.15.jar MyPet/mongo-java-driver.jar MyPet/mongo-java-driver-3.12.11.jar",
"Main-Class" to "de.Keyle.MyPet.Main",
"Project-Name" to project.name,
"Project-Version" to fullVersion,
"Project-Build" to (System.getenv("BUILD_NUMBER") ?: ""),
"Project-Type" to buildType,
"Project-Minecraft-Version" to minecraftVersion,
"Project-Bukkit-Packets" to bukkitPackets,
"Special-MC-Versions" to specialVersions,
"Git-Commit" to (System.getenv("GIT_COMMIT") ?: "")
)
)
tasks.named<Jar>("jar") {
archiveBaseName.set(archivesBaseName)
archiveFileName.set("${archivesBaseName}-${fullVersion}.jar")
archiveVersion.set(fullVersion)
manifest { attributesForMyPet() }
}
/* ---------- Shading without JVM attribute conflicts ---------- */
// Create a resolvable-only configuration to collect jars to shade.
val shade by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
// Mark as runtime usage and leave TargetJvmVersion unset.
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
}
dependencies {
// Pull submodules as built jars (regardless of their target JVM)
add("shade", project(path = ":plugin", configuration = "runtimeElements"))
add("shade", project(path = ":api", configuration = "runtimeElements"))
add("shade", project(path = ":skills", configuration = "runtimeElements"))
nmsModules.forEach { add("shade", project(path = it, configuration = "runtimeElements")) }
// External libs to be shaded
add("shade", "org.bstats:bstats-bukkit:3.1.0")
add("shade", "org.mongodb:mongodb-driver:3.12.11")
add("shade", "de.keyle:knbt:0.0.6")
add("shade", "com.google.code.gson:gson:2.8.9")
add("shade", "io.sentry:sentry:8.22.0")
add("shade", "io.sentry:sentry-logback:8.22.0")
add("shade", "com.zaxxer:HikariCP:3.4.2")
}
// Build the shaded jar strictly from the 'shade' configuration
val shadowJar = tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
archiveBaseName.set(archivesBaseName)
archiveVersion.set(fullVersion)
archiveClassifier.set("")
exclude("META-INF/**")
manifest { attributesForMyPet() }
dependsOn(shade)
configurations = listOf(shade)
relocate("org.bstats", "de.Keyle.MyPet.util.metrics")
relocate("com.zaxxer.hikari", "de.Keyle.MyPet.util.hikari")
relocate("de.keyle.knbt", "de.Keyle.MyPet.util.nbt")
relocate("org.bson", "de.Keyle.MyPet.util.bson")
relocate("com.google.gson", "de.Keyle.MyPet.util.gson")
relocate("com.mongodb", "de.Keyle.MyPet.util.mongodb")
relocate("io.sentry", "de.Keyle.MyPet.util.sentry")
}
tasks.named("assemble") { dependsOn(shadowJar) }
tasks.named("build") { dependsOn(shadowJar) }
/* ---------- Sentry Configuration ---------- */
sentry {
// Only bundle sources when auth token is available (snapshot/release builds)
// PR builds don't have the token and don't need source bundling
includeSourceContext = !System.getenv("SENTRY_AUTH_TOKEN").isNullOrEmpty()
org = "mypet"
projectName = "mypet"
authToken = System.getenv("SENTRY_AUTH_TOKEN")
// The actual code lives in the api/plugin/nms subprojects, but the shipped artifact is a single
// shaded jar built here at the root with ONE sentry-debug-meta.properties. Enabling source
// context per-subproject would emit colliding debug-meta files that shadowJar silently dedups,
// so instead we fold every module's source root into this project's single source bundle. One
// bundle id, one properties file, all sources -> stack frames across all modules symbolicate.
val moduleSourceDirs = (listOf("api", "plugin") +
file("nms").listFiles().orEmpty()
.filter { it.isDirectory && File(it, "src/main/java").isDirectory }
.map { "nms/${it.name}" })
.map { "$it/src/main/java" }
.filter { file(it).isDirectory }
additionalSourceDirsForSourceContext.set(moduleSourceDirs)
}
/* ---------- Root compilation settings (Java 8 output) ---------- */
java {
toolchain { languageVersion.set(JavaLanguageVersion.of(25)) }
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(8)
options.encoding = "UTF-8"
}
/* ---------- Hangar Release ---------- */
hangarPublish {
publications.register("plugin") {
val hangarVersion = providers.gradleProperty("HANGAR_VERSION").orNull
?: project.version.toString()
val hangarFile = providers.gradleProperty("HANGAR_FILE").orNull
?: "build/libs/MyPet-${fullVersion}.jar"
val hangarChangelog = providers.gradleProperty("HANGAR_CHANGELOG").orNull
?: "View the full changelog on Modrinth: https://modrinth.com/plugin/mypet/version/$hangarVersion"
version.set(hangarVersion)
id.set("MyPet")
channel.set(if (buildType == "release") "Release" else "Snapshot")
changelog.set(hangarChangelog)
apiKey.set(
providers.gradleProperty("HANGAR_TOKEN").orNull
?: System.getenv("HANGAR_TOKEN")
?: ""
)
platforms {
paper {
jar.set(file(hangarFile))
platformVersions.set(listOf(
"1.8.8", "1.12.2", "1.16.5", "1.17.1", "1.18.2",
"1.19.x", "1.20.x", "1.21.x", "26.1", "26.2"
))
}
}
}
}