-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbuild.gradle
More file actions
414 lines (366 loc) · 14.3 KB
/
Copy pathbuild.gradle
File metadata and controls
414 lines (366 loc) · 14.3 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
// Spotless requires JVM 11+; NMCP requires JVM 17+
// Only add classpath entries when building with a compatible JVM so older JDK builds succeed
buildscript {
repositories { gradlePluginPortal() }
dependencies {
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
}
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
classpath 'com.gradleup.nmcp:nmcp:1.4.4'
}
}
}
plugins {
id 'java'
id 'jacoco'
id 'java-library'
id 'maven-publish'
id 'signing'
}
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
apply plugin: 'com.gradleup.nmcp'
apply plugin: 'com.gradleup.nmcp.aggregation'
}
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
apply plugin: 'com.diffplug.spotless'
spotless {
java {
eclipse()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
}
group 'com.surrealdb'
version '2.1.2'
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
// Use --release to enforce both bytecode version and API surface at compile time.
// This prevents accidental use of APIs introduced after Java 8 (e.g. String.isBlank()),
// which would compile fine on a modern JDK but fail at runtime on Java 8.
// Note: --release flag is only supported on JDK 9+.
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
tasks.withType(JavaCompile).configureEach {
options.release = 8
}
}
sourceSets {
integrationTest {
java
}
// Java-record-using tests live in their own source set so the main library
// and the standard test suite remain compilable with --release 8.
// The set is always created (so configuration-time references resolve);
// compilation and execution are conditional on JDK 16+ below.
recordTest {
java {
srcDirs 'src/recordTest/java'
}
compileClasspath += sourceSets.main.output + sourceSets.test.output
runtimeClasspath += sourceSets.main.output + sourceSets.test.output
}
}
configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
recordTestImplementation.extendsFrom testImplementation
recordTestRuntimeOnly.extendsFrom testRuntimeOnly
}
ext.nativeJar = file("native/surrealdb-${version}.jar")
// Fail fast, but only when the task graph contains a task that needs the file
gradle.taskGraph.whenReady { graph ->
boolean needsNativeJar = graph.allTasks.any { t ->
t.name in ['publish', 'publishToMavenLocal'] ||
(t.name.startsWith('generate') && t.name.endsWith('Publication'))
}
if (needsNativeJar && !nativeJar.exists()) {
throw new GradleException(
"Native JAR not found at '${nativeJar}'. " +
"Build/copy it to native/ before running publishing tasks."
)
}
}
// ---------------------------------------------------------------------------
// 2. Task that stages (copies) the external JAR into build/libs
// ---------------------------------------------------------------------------
tasks.register('stageNativeJar', Copy) {
description = 'Copies the externally built JAR (with native libs) into build/libs.'
group = 'build'
from nativeJar
into "$buildDir/libs"
rename { "surrealdb-${version}.jar" } // the file name expected by publish/sign
}
// ---------------------------------------------------------------------------
// 3. Make sure every task that cares about the JAR sees the staged version.
// • jar is still executed (keeps components.java happy), but the copy task
// will overwrite its output afterwards.
// ---------------------------------------------------------------------------
tasks.named('jar') {
finalizedBy 'stageNativeJar' // run jar first, then overwrite
}
// All publish-to-Maven tasks must wait for the staged JAR
tasks.withType(PublishToMavenRepository).configureEach {
dependsOn 'stageNativeJar'
}
// Metadata / POM generation tasks must wait as well
tasks.matching { it.name.startsWith('generate') && it.name.endsWith('Publication') }
.configureEach { dependsOn 'stageNativeJar' }
// The generated signing task is created after evaluation; use task rules
tasks.matching { it.name == 'signMavenJavaPublication' }.configureEach {
dependsOn 'stageNativeJar'
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
// classes produced by src/main/java
integrationTestImplementation sourceSets.main.output
// the staged, native-enabled JAR
integrationTestImplementation files("native/surrealdb-${version}.jar")
}
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
dependencies {
// NMCP aggregation: include this project's publications
nmcpAggregation project(":")
}
}
jacoco {
toolVersion = "0.8.12"
}
// Build Rust native library so tests can load it
def nativeLibName = System.getProperty('os.name').toLowerCase().contains('mac') ? 'libsurrealdb.dylib' : (System.getProperty('os.name').toLowerCase().contains('win') ? 'surrealdb.dll' : 'libsurrealdb.so')
tasks.register('cargoBuild', Exec) {
description = 'Builds the Rust native library (debug) for tests'
group = 'build'
commandLine 'cargo', 'build'
workingDir projectDir
// Always build so test JVM loads a lib that matches current Java/Rust code (avoids UnsatisfiedLinkError)
}
tasks.register('cargoBuildRelease', Exec) {
description = 'Builds the Rust native library (release)'
group = 'build'
commandLine 'cargo', 'build', '--release'
workingDir projectDir
}
test {
useJUnitPlatform()
dependsOn cargoBuild
// Explicit path so tests load the built native lib regardless of java.library.path
def nativeLibFile = file("target/debug/${nativeLibName}")
def nativeLibPath = nativeLibFile.absolutePath
systemProperty 'surrealdb.native.path', nativeLibPath
jvmArgs "-Dsurrealdb.native.path=${nativeLibPath}"
// Also set java.library.path for fallback
def debugDir = new File(projectDir, 'target/debug').absolutePath
def releaseDir = new File(projectDir, 'target/release').absolutePath
def libPath = debugDir + File.pathSeparator + releaseDir
systemProperty 'java.library.path', libPath
jvmArgs "-Djava.library.path=${libPath}"
// Per-test timeout so a single test cannot hang the suite (may not interrupt native/JNI blocks)
systemProperty 'junit.jupiter.execution.timeout.default', '15s'
maxParallelForks = 1
// To pinpoint where the run gets stuck, uncomment and run with short timeout (e.g. ./test-with-timeout.sh 25):
// beforeTest { d -> logger.lifecycle("[{}] START {} > {}", System.currentTimeMillis(), d.className, d.name) }
// afterTest { d, r -> logger.lifecycle("[{}] END {} > {} => {}", System.currentTimeMillis(), d.className, d.name, r.resultType) }
testLogging {
events "passed", "failed", "skipped"
// Also emit the events at INFO level, otherwise `gradlew -i` (as used
// in CI) hides them: Gradle switches to the per-level event set, which
// is empty by default.
info {
events "passed", "failed", "skipped"
}
showStackTraces = true
exceptionFormat = "full"
}
}
// Records require JDK 16+ at compile time. Only wire up the recordTest task graph
// when the build JDK supports them; on older JDKs the source set is created but
// its compile/test tasks are disabled, so JDK 8/11 builds remain green.
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
tasks.named('compileRecordTestJava') {
options.release = 16
}
tasks.register('recordTest', Test) {
description = 'Runs the Java-record tests (requires JDK 16+).'
group = 'verification'
useJUnitPlatform()
dependsOn cargoBuild
testClassesDirs = sourceSets.recordTest.output.classesDirs
classpath = sourceSets.recordTest.runtimeClasspath
def nativeLibFile = file("target/debug/${nativeLibName}")
def nativeLibPath = nativeLibFile.absolutePath
systemProperty 'surrealdb.native.path', nativeLibPath
jvmArgs "-Dsurrealdb.native.path=${nativeLibPath}"
def debugDir = new File(projectDir, 'target/debug').absolutePath
def releaseDir = new File(projectDir, 'target/release').absolutePath
def libPath = debugDir + File.pathSeparator + releaseDir
systemProperty 'java.library.path', libPath
jvmArgs "-Djava.library.path=${libPath}"
systemProperty 'junit.jupiter.execution.timeout.default', '15s'
maxParallelForks = 1
testLogging {
events "passed", "failed", "skipped"
info {
events "passed", "failed", "skipped"
}
showStackTraces = true
exceptionFormat = "full"
}
}
tasks.named('check') { dependsOn 'recordTest' }
} else {
// Disable the auto-generated tasks for the recordTest source set on older JDKs.
tasks.named('compileRecordTestJava') { enabled = false }
tasks.matching { it.name == 'processRecordTestResources' }.configureEach { enabled = false }
// Disabled placeholder so `gradlew recordTest` is invocable on every JDK
// (the CI matrix runs it on all legs); it reports SKIPPED instead of
// failing with "task not found".
tasks.register('recordTest') {
description = 'Runs the Java-record tests (requires JDK 16+; skipped on this JDK).'
group = 'verification'
enabled = false
}
}
jacocoTestReport {
dependsOn test
finalizedBy jacocoTestCoverageVerification
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.5
}
}
}
}
tasks.register('createCombinedReport') {
dependsOn jacocoTestReport
dependsOn javadoc
doLast {
// Copy the javadoc
def javadocSource = file("build/docs/javadoc")
def javadocDestination = file("build/reports/javadoc")
// Ensure destination exists and copy
delete javadocDestination // Clean old docs if present
mkdir javadocDestination
copy {
from javadocSource
into javadocDestination
}
def indexFile = file("build/reports/index.html")
indexFile.text = """
<!DOCTYPE html>
<html>
<head>
<title>Combined Test, Coverage, and Javadoc Report</title>
</head>
<body>
<h1>Combined Test, Coverage, and Javadoc Report</h1>
<ul>
<li><a href="./tests/test/index.html">Test Report</a></li>
<li><a href="./jacoco/test/html/index.html">JaCoCo Coverage Report</a></li>
<li><a href="./javadoc/index.html">Javadoc</a></li>
</ul>
</body>
</html>
"""
}
}
tasks.register('integrationTest', Test) {
dependsOn 'stageNativeJar'
useJUnitPlatform()
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
// use target/release for a release build
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat = 'full'
showCauses = true
showStackTraces = true
}
}
project.afterEvaluate {
def key = System.getenv('SIGNING_KEY')
def _pass = System.getenv('SIGNING_KEY_PASS')
signing {
useInMemoryPgpKeys(key, _pass)
sign publishing.publications.mavenJava
}
}
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
nmcpAggregation {
centralPortal {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
publishingType = "AUTOMATIC"
}
}
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/surrealdb/surrealdb.java")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
mavenJava(MavenPublication) {
groupId = project.group
artifactId = project.rootProject.name
version = project.version
from components.java
pom {
name = 'SurrealDB Driver'
packaging = 'jar'
description = 'The driver for accessing a SurrealDB instance.'
url = 'https://surrealdb.com/docs/integration/libraries/java'
scm {
connection = 'scm:git:git@github.com:surrealdb/surrealdb.java.git'
url = 'https://github.com/surrealdb/surrealdb.java'
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'tobiemh'
name = 'Tobie Morgan Hitchcock'
email = 'tobie@surrealdb.com'
}
developer {
id = 'macjuul'
name = 'Julian Mills'
email = 'julian.mills@surrealdb.com'
}
developer {
id = 'kearfy'
name = 'Micha de Vries'
email = 'micha.de.vries@surrealdb.com'
}
developer {
id = 'emmanuel-keller'
name = 'Emmanuel Keller'
email = 'emmanuel.keller@surrealdb.com'
}
}
}
}
}
}