Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
338 lines (295 loc) · 11.5 KB
/
Copy pathbuild.gradle
File metadata and controls
338 lines (295 loc) · 11.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
plugins {
id 'java'
id 'checkstyle'
id 'maven-publish'
id 'com.gradleup.shadow' version '9.3.1'
id 'io.sentry.jvm.gradle' version '6.1.0'
}
group = 'com.hyperfactions'
version = '0.14.0'
// Shared version property avoids accessing project at execution time
def buildVersion = objects.property(String).convention(version)
// Override version for dev builds
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(':buildDev')) {
project.version = '0.0.0'
buildVersion.set('0.0.0')
}
}
// Resolve Hytale server version (standalone fallback for JitPack / CI builds)
def hytaleChannel = (findProperty('hytale_channel') ?: 'release').toString().trim()
def hytaleServerVersion = {
// Prefer root project version (monorepo), fall back to self-resolution
if (rootProject.hasProperty('hytaleVersion')) return rootProject.hytaleVersion
def override = (findProperty('hytale_server_version') ?: '').toString().trim()
if (override) return override
try {
def url = "https://maven.hytale.com/${hytaleChannel}/com/hypixel/hytale/Server/maven-metadata.xml"
def text = new URI(url).toURL().text
def m = text =~ /<release>(.+?)<\/release>/
if (m.find()) return m.group(1)
} catch (ignored) {}
throw new GradleException("Could not resolve Hytale server version")
}()
// Detect monorepo vs standalone (JitPack / CI) build context
def isMonorepo = rootProject.name == 'HyperSystems'
// Check if optional local dependencies are available (WiFlowExpansion needs WiFlow API to compile)
def hasWiFlowLib = file('libs').listFiles()?.any { it.name.contains('WiFlow') } ?: false
// HyperPerms may be provided as a local jar in libs/ (dev) instead of resolved from JitPack (CI)
def hasHyperPermsLib = file('libs').listFiles()?.any { it.name.contains('HyperPerms') } ?: false
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
repositories {
mavenCentral()
maven { url = "https://maven.hytale.com/${hytaleChannel}" }
maven { url = 'https://repo.helpch.at/releases/' }
if (!isMonorepo) {
// Standalone build: resolve HyperPerms from JitPack
maven { url = 'https://jitpack.io' }
}
}
dependencies {
// Hytale Server API
compileOnly "com.hypixel.hytale:Server:${hytaleServerVersion}"
// HyperPerms soft dependency (for compile-time reference only).
// Local dev provides libs/HyperPerms.jar (picked up by the libs fileTree below);
// CI/JitPack builds without it resolve from the published tag.
if (isMonorepo) {
compileOnly project(':HyperPerms')
} else if (!hasHyperPermsLib) {
compileOnly 'com.github.HyperSystems-Development:HyperPerms:v2.9.6'
}
// JSON handling
implementation 'com.google.code.gson:gson:2.11.0'
// Sentry error tracking (bundled in shadow JAR)
implementation 'io.sentry:sentry:8.33.0'
// PlaceholderAPI Hytale (soft dependency - compileOnly)
compileOnly 'at.helpch:placeholderapi-hytale:1.0.4'
// Optional local soft dependencies (only available in monorepo dev environment)
// WiFlowPlaceholderAPI and GravestonePlugin integrations use reflection so the build
// succeeds without them. WiFlowExpansion.java is conditionally excluded below.
// Exclude any local Hytale Server jar: the server API must come exclusively from the
// channel-resolved maven dependency (-Phytale_channel), otherwise a stale HytaleServer.jar
// dropped in libs/ would silently shadow it and defeat the release/pre-release switch.
compileOnly fileTree('libs') { include '*.jar'; exclude 'HytaleServer*.jar', 'Server-*.jar' }
// Null safety annotations
compileOnly 'org.jetbrains:annotations:24.1.0'
testCompileOnly 'org.jetbrains:annotations:24.1.0'
// Testing
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
// WiFlowExpansion extends PlaceholderExpansion (from WiFlowPlaceholderAPI) directly.
// When WiFlow isn't on the classpath (JitPack / CI), exclude it from compilation.
// The bridge class (WiFlowPlaceholderIntegration) loads it reflectively at runtime.
if (!hasWiFlowLib) {
sourceSets.main.java.exclude '**/WiFlowExpansion.java'
}
// Generate BuildInfo.java with project version
def generatedSrcDir = layout.buildDirectory.dir("generated/sources/buildinfo/java")
sourceSets.main.java.srcDir(generatedSrcDir)
tasks.register('generateBuildInfo') {
def outputDir = generatedSrcDir
def ver = buildVersion
inputs.property('version', ver)
outputs.dir(outputDir)
doLast {
def v = ver.get()
def dir = outputDir.get().asFile.toPath().resolve("com/hyperfactions").toFile()
dir.mkdirs()
new File(dir, "BuildInfo.java").text = """\
package com.hyperfactions;
/**
* Auto-generated build information.
*/
public final class BuildInfo {
public static final String VERSION = "${v}";
public static final String JAVA_VERSION = "${System.getProperty('java.version')}";
public static final long BUILD_TIMESTAMP = ${System.currentTimeMillis()}L;
private BuildInfo() {}
}
"""
}
}
// Generate help .lang files from markdown sources
tasks.register('generateHelpLang', JavaExec) {
group = 'build'
description = 'Generate help .lang files from markdown sources'
dependsOn 'compileJava'
classpath = sourceSets.main.compileClasspath + files(sourceSets.main.java.classesDirectory)
mainClass = 'com.hyperfactions.build.HelpLangGenerator'
args = [
file('src/main/resources/Server/Languages').absolutePath,
layout.buildDirectory.dir('generated/resources').get().asFile.absolutePath
]
inputs.dir(file('src/main/resources/Server/Languages'))
outputs.dir(layout.buildDirectory.dir('generated/resources'))
}
sourceSets.main.resources.srcDir(layout.buildDirectory.dir('generated/resources'))
// Check translations: compare keys in en-US against other locales
tasks.register('checkTranslations') {
group = 'verification'
description = 'Report missing translation keys compared to en-US'
doLast {
def langDir = file('src/main/resources/Server/Languages')
def enDir = new File(langDir, 'en-US')
if (!enDir.exists()) {
println "No en-US directory found at ${enDir.absolutePath}"
return
}
// Collect en-US keys per file
def enKeys = [:]
enDir.listFiles({ f -> f.name.endsWith('.lang') } as FileFilter).each { f ->
def keys = []
f.eachLine { line ->
line = line.trim()
if (line && !line.startsWith('#') && line.contains('=')) {
keys << line.substring(0, line.indexOf('=')).trim()
}
}
enKeys[f.name] = keys
}
// Check each locale
def locales = langDir.listFiles({ f -> f.isDirectory() && f.name != 'en-US' } as FileFilter)
if (!locales) {
println "No non-English locales found."
return
}
def totalMissing = 0
locales.sort { it.name }.each { localeDir ->
def localeMissing = 0
enKeys.each { fileName, keys ->
def localeFile = new File(localeDir, fileName)
if (!localeFile.exists()) {
println "[${localeDir.name}] MISSING FILE: ${fileName} (${keys.size()} keys)"
localeMissing += keys.size()
return
}
def localeKeys = []
localeFile.eachLine { line ->
line = line.trim()
if (line && !line.startsWith('#') && line.contains('=')) {
localeKeys << line.substring(0, line.indexOf('=')).trim()
}
}
def missing = keys.findAll { !localeKeys.contains(it) }
if (missing) {
println "[${localeDir.name}] ${fileName}: ${missing.size()} missing keys"
missing.each { println " - ${it}" }
localeMissing += missing.size()
}
}
if (localeMissing == 0) {
println "[${localeDir.name}] All keys present"
}
totalMissing += localeMissing
}
println "\nTotal missing keys across all locales: ${totalMissing}"
}
}
// Expand version placeholder in manifest.json
processResources {
def ver = buildVersion
def srvVer = hytaleServerVersion
inputs.property('version', ver)
inputs.property('serverVersion', srvVer)
filesMatching('manifest.json') {
expand(version: ver.get(), serverVersion: srvVer)
}
}
jar {
archiveClassifier = 'plain'
}
shadowJar {
archiveClassifier.set('')
// Relocate dependencies to avoid conflicts
relocate 'com.google.gson', 'com.hyperfactions.lib.gson'
relocate 'io.sentry', 'com.hyperfactions.lib.sentry'
// Don't minimize - it removes Gson's inner classes needed at runtime
}
test {
useJUnitPlatform()
}
checkstyle {
toolVersion = '10.26.1'
configFile = file('config/checkstyle/checkstyle.xml')
ignoreFailures = true
showViolations = true
}
tasks.withType(Checkstyle).configureEach {
reports {
xml.required = true
html.required = true
}
}
build {
dependsOn shadowJar
finalizedBy tasks.matching { it.name == 'sentryUploadSourceBundleJava' }
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs.addAll(['-Xlint:all', '-Xlint:-processing'])
}
javadoc {
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
options.memberLevel = JavadocMemberLevel.PUBLIC
options.addStringOption('Xdoclint:none', '-quiet')
options.links(
'https://docs.oracle.com/en/java/javase/21/docs/api/'
)
failOnError = false
}
// Ensure help lang files are generated before processResources copies them
tasks.named('processResources') {
dependsOn 'generateHelpLang'
}
// Ensure build info is generated and HyperPerms shadowJar is built before compiling
tasks.named('compileJava') {
dependsOn 'generateBuildInfo'
if (isMonorepo) {
dependsOn ':HyperPerms:shadowJar'
}
}
// Sentry tasks use the same generated sources dir as generateBuildInfo — declare dependencies
tasks.matching { it.name.startsWith('sentry') || it.name.startsWith('generateSentry') }.configureEach {
dependsOn 'generateBuildInfo'
}
// Dev build task - clean build with version set to 'dev'
tasks.register('buildDev') {
group = 'build'
description = 'Clean build with dev version identifier'
dependsOn 'clean', 'build'
}
tasks.named('build') {
mustRunAfter 'clean'
}
// Sentry source context upload (reads token from .sentry-auth-token file or SENTRY_AUTH_TOKEN env var)
sentry {
includeSourceContext = true
org = "hypersystems"
projectName = "hyperfactions"
authToken = {
def tokenFile = file('.sentry-auth-token')
if (tokenFile.exists()) return tokenFile.text.trim()
return System.getenv("SENTRY_AUTH_TOKEN")
}()
}
// Maven publication for JitPack (publishes API classes, not the shadow JAR)
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
groupId = 'com.hyperfactions'
artifactId = 'HyperFactions'
// Strip all dependencies from the POM — consumers provide their own
pom.withXml {
def deps = asNode().dependencies
if (deps) deps.each { asNode().remove(it) }
}
}
}
}