-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
211 lines (173 loc) · 6.71 KB
/
build.gradle
File metadata and controls
211 lines (173 loc) · 6.71 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
plugins {
id 'java'
id 'com.gradleup.shadow' version '9.3.1'
}
group = project.mod_group
version = project.mod_version
// ---------------------------------------------------------------------------
// Hytale Maven version resolution
// Fetches the latest release from maven.hytale.com at build time.
// Use -Phytale_channel=pre-release (or run ./gradlew buildPreRelease)
// to target the pre-release channel instead.
// ---------------------------------------------------------------------------
def resolveHytaleVersion(String channel) {
def url = "https://maven.hytale.com/${channel}/com/hypixel/hytale/Server/maven-metadata.xml"
def text = new URL(url).text
def matcher = text =~ /<release>(.+?)<\/release>/
if (!matcher.find()) throw new GradleException("Could not resolve Hytale server version from ${url}")
return matcher.group(1)
}
def hytaleChannel = project.findProperty('hytale_channel') ?: 'release'
def hytaleVersion = resolveHytaleVersion(hytaleChannel)
// 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')
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(project.java_version.toInteger())
}
}
repositories {
mavenCentral()
maven { url "https://maven.hytale.com/${hytaleChannel}" }
// PlaceholderAPI for Hytale
maven { url = 'https://repo.helpch.at/releases/' }
}
dependencies {
// Hytale Server API — resolved automatically from maven.hytale.com
compileOnly "com.hypixel.hytale:Server:${hytaleVersion}"
// Note: HyFactions is a soft dependency using pure reflection
// No compile-time dependency needed - just runtime class detection
// JSON handling
implementation 'com.google.code.gson:gson:2.11.0'
// High-performance caching (L1 cache)
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
// YAML parsing (for LuckPerms migration)
implementation 'org.yaml:snakeyaml:2.2'
// Database - HikariCP connection pooling
implementation 'com.zaxxer:HikariCP:6.2.1'
// Database - SQLite JDBC driver (optional - user must download separately)
// The driver is NOT bundled to keep JAR size small (~4MB vs ~15MB)
// Users who want SQLite features must download the JAR to plugins/HyperPerms/lib/
compileOnly 'org.xerial:sqlite-jdbc:3.45.1.0'
// Database - MariaDB JDBC driver
implementation 'org.mariadb.jdbc:mariadb-java-client:3.5.1'
// Redis client for pub/sub and L2 cache (P5 - deferred)
// implementation 'io.lettuce:lettuce-core:6.5.2.RELEASE'
// Null safety annotations
compileOnly 'org.jetbrains:annotations:26.0.1'
// VaultUnlocked API (soft dependency - compileOnly)
compileOnly files('libs/VaultUnlocked-Hytale-2.19.0.jar')
// PlaceholderAPI Hytale (soft dependency - compileOnly)
compileOnly 'at.helpch:placeholderapi-hytale:1.0.4'
// Testing
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.4'
}
// 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/hyperperms").toFile()
dir.mkdirs()
new File(dir, "BuildInfo.java").text = """\
package com.hyperperms;
/**
* 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() {}
}
"""
}
}
tasks.named('compileJava') {
dependsOn 'generateBuildInfo'
}
// Expand version placeholders in manifest.json
processResources {
def ver = buildVersion
inputs.property('version', ver)
inputs.property('serverVersion', hytaleVersion)
filesMatching('manifest.json') {
expand(version: ver.get(), serverVersion: hytaleVersion)
}
}
// Prevent the plain jar task from overwriting the shadow JAR
// (both default to empty classifier; in multi-project builds the jar task
// runs after shadowJar for project dependencies and would clobber it)
jar {
archiveClassifier = 'plain'
}
shadowJar {
archiveClassifier.set('')
// Relocate dependencies to avoid conflicts
relocate 'com.google.gson', 'com.hyperperms.lib.gson'
relocate 'com.github.benmanes.caffeine', 'com.hyperperms.lib.caffeine'
relocate 'org.yaml.snakeyaml', 'com.hyperperms.lib.snakeyaml'
// Note: SQLite JDBC cannot be relocated due to native library loading
relocate 'com.zaxxer.hikari', 'com.hyperperms.lib.hikari'
// Note: MariaDB JDBC is NOT relocated because the shadow plugin does not
// rewrite META-INF/services files, breaking the driver's internal
// ServiceLoader-based plugin discovery (auth plugins, codecs, etc.).
// Future relocations:
// relocate 'io.lettuce', 'com.hyperperms.lib.lettuce'
}
test {
useJUnitPlatform()
// Enable virtual threads for tests (Java 21+)
jvmArgs '--enable-preview'
testLogging {
events 'passed', 'skipped', 'failed'
showStandardStreams = true
}
}
build {
dependsOn shadowJar
}
// ---------------------------------------------------------------------------
// Build tasks
// ---------------------------------------------------------------------------
tasks.register('buildDev') {
group = 'build'
description = 'Clean build with dev version identifier'
dependsOn 'clean', 'build'
}
tasks.named('build') {
mustRunAfter 'clean'
}
tasks.register('buildRelease', GradleBuild) {
group = 'build'
description = 'Clean build against the latest Hytale release server'
tasks = ['clean', 'shadowJar']
startParameter.projectProperties = ['hytale_channel': 'release']
}
tasks.register('buildPreRelease', GradleBuild) {
group = 'build'
description = 'Clean build against the latest Hytale pre-release server'
tasks = ['clean', 'shadowJar']
startParameter.projectProperties = ['hytale_channel': 'pre-release']
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs.addAll([
'-Xlint:all',
'-Xlint:-processing',
'--enable-preview'
])
}