-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
128 lines (105 loc) · 2.99 KB
/
build.gradle
File metadata and controls
128 lines (105 loc) · 2.99 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
plugins {
id 'java'
id 'com.gradleup.shadow' version '9.3.1'
}
group = 'dev.hypersystems.hyperguard'
version = '1.0.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')
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
repositories {
mavenCentral()
}
dependencies {
// Hytale Server API (provided at runtime)
compileOnly files('libs/HytaleServer.jar')
// JSON handling
implementation 'com.google.code.gson:gson:2.11.0'
// Null safety annotations
compileOnly 'org.jetbrains:annotations:26.0.1'
// 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("dev/hypersystems/hyperguard").toFile()
dir.mkdirs()
new File(dir, "BuildInfo.java").text = """\
package dev.hypersystems.hyperguard;
/**
* 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 placeholder in manifest.json
processResources {
def ver = buildVersion
inputs.property('version', ver)
filesMatching('manifest.json') {
expand(version: ver.get())
}
}
shadowJar {
archiveClassifier.set('')
// Relocate dependencies to avoid conflicts
relocate 'com.google.gson', 'dev.hypersystems.hyperguard.lib.gson'
}
test {
useJUnitPlatform()
// Enable virtual threads for tests (Java 21+)
jvmArgs '--enable-preview'
testLogging {
events 'passed', 'skipped', 'failed'
showStandardStreams = true
}
}
build {
dependsOn 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'
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs.addAll([
'-Xlint:all',
'-Xlint:-processing',
'--enable-preview'
])
}