forked from ItsZib/AdvancedPlaytime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
191 lines (159 loc) · 5.89 KB
/
build.gradle
File metadata and controls
191 lines (159 loc) · 5.89 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
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 URI(url).toURL().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 = (findProperty('hytale_channel') ?: 'release').toString().trim()
def hytaleVersion = resolveHytaleVersion(hytaleChannel)
// Detect monorepo vs standalone build context
def isMonorepo = rootProject.name == 'HyperSystems'
// 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}" }
}
dependencies {
// Hytale Server API — resolved automatically from maven.hytale.com
compileOnly "com.hypixel.hytale:Server:${hytaleVersion}"
// HyperPerms soft dependency — accessed via reflection at runtime only
// In monorepo context, include for IDE autocompletion
if (isMonorepo) {
compileOnly project(':HyperPerms')
}
// JSON handling
implementation 'com.google.code.gson:gson:2.11.0'
// Database - HikariCP connection pooling
implementation 'com.zaxxer:HikariCP:6.2.1'
// SLF4J 2.x — overrides HikariCP's transitive 1.7.x to eliminate
// "Failed to load class StaticLoggerBinder" warning (2.x uses ServiceLoader)
implementation 'org.slf4j:slf4j-api:2.0.16'
implementation 'org.slf4j:slf4j-nop:2.0.16'
// Database - MySQL JDBC driver
implementation 'com.mysql:mysql-connector-j:8.4.0'
// Database - SQLite JDBC driver
implementation 'org.xerial:sqlite-jdbc:3.46.0.0'
// Null safety annotations
compileOnly 'org.jetbrains:annotations:26.0.1'
// Testing
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.4'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.mockito:mockito-core:5.15.2'
}
// ---------------------------------------------------------------------------
// BuildInfo generation
// ---------------------------------------------------------------------------
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/hypersystems/hyperrewards").toFile()
dir.mkdirs()
new File(dir, "BuildInfo.java").text = """\
package com.hypersystems.hyperrewards;
/**
* 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'
if (isMonorepo) {
dependsOn ':HyperPerms:shadowJar'
}
}
// 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
jar {
archiveClassifier = 'plain'
}
shadowJar {
archiveClassifier.set('')
// Relocate dependencies to avoid conflicts with other plugins
relocate 'com.google.gson', 'com.hypersystems.hyperrewards.lib.gson'
relocate 'com.zaxxer.hikari', 'com.hypersystems.hyperrewards.lib.hikari'
relocate 'org.slf4j', 'com.hypersystems.hyperrewards.lib.slf4j'
}
build {
dependsOn shadowJar
}
test {
useJUnitPlatform()
}
// ---------------------------------------------------------------------------
// 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'
])
}