-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
223 lines (188 loc) · 6.55 KB
/
Copy pathbuild.gradle
File metadata and controls
223 lines (188 loc) · 6.55 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
plugins {
id 'java'
id 'checkstyle'
id 'maven-publish'
id 'com.gradleup.shadow' version '9.3.1'
}
group = 'com.hyperfactions'
version = '0.10.2'
// 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
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)
if (isMonorepo) {
compileOnly project(':HyperPerms')
} else {
compileOnly 'com.github.HyperSystemsDev:HyperPerms:v2.8.5'
}
// JSON handling
implementation 'com.google.code.gson:gson:2.11.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.
compileOnly fileTree('libs') { include '*.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() {}
}
"""
}
}
// 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'
// 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
}
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 build info is generated and HyperPerms shadowJar is built before compiling
tasks.named('compileJava') {
dependsOn 'generateBuildInfo'
if (isMonorepo) {
dependsOn ':HyperPerms:shadowJar'
}
}
// 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'
}
// 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) }
}
}
}
}