-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbuild.gradle
More file actions
300 lines (257 loc) · 9.58 KB
/
build.gradle
File metadata and controls
300 lines (257 loc) · 9.58 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
import me.champeau.jmh.JmhBytecodeGeneratorTask
import org.gradle.internal.os.OperatingSystem
import java.time.Duration
plugins {
id 'java'
id 'scala'
id 'me.champeau.jmh' version '0.7.1'
id 'pl.allegro.tech.build.axion-release' version '1.21.1'
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id 'maven-publish'
id 'signing'
}
scmVersion {
versionCreator('versionWithBranch')
tag {
prefix.set('')
}
}
group = 'org.simdjson'
version = scmVersion.version
repositories {
mavenCentral()
}
// --- Java Version Resolution ---
static int resolveBuildJavaVersion() {
String v = System.getenv('BUILD_JAVA_VERSION') ?: JavaVersion.current().majorVersion
int dot = v.indexOf('.')
if (dot >= 0) {
v = v.substring(0, dot)
}
int dash = v.indexOf('-')
if (dash >= 0) {
v = v.substring(0, dash)
}
try {
return Integer.parseInt(v)
} catch (Exception e) {
throw new GradleException("Invalid BUILD_JAVA_VERSION '${System.getenv('BUILD_JAVA_VERSION')}'. " +
"Expected a Java major version like '24' (optionally with suffixes like '24.0.1' or '24-ea').", e)
}
}
def buildJavaVersion = resolveBuildJavaVersion()
if (buildJavaVersion < 24) {
throw new GradleException(
"This build requires Java 24+.\n" +
"Detected buildJavaVersion=${buildJavaVersion}.\n" +
"Either run Gradle with JDK 24+ (JAVA_HOME / PATH), or set BUILD_JAVA_VERSION=24 (or higher)."
)
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(buildJavaVersion)
}
withJavadocJar()
withSourcesJar()
sourceCompatibility = JavaVersion.toVersion(buildJavaVersion)
targetCompatibility = JavaVersion.toVersion(buildJavaVersion)
}
ext {
junitVersion = '5.12.0'
jsoniterScalaVersion = '2.33.2'
}
dependencies {
jmhImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.18.2'
jmhImplementation group: 'com.alibaba.fastjson2', name: 'fastjson2', version: '2.0.56'
jmhImplementation group: 'com.github.plokhotnyuk.jsoniter-scala', name: 'jsoniter-scala-core_2.13', version: jsoniterScalaVersion
jmhImplementation group: 'com.google.guava', name: 'guava', version: '33.4.0-jre'
compileOnly group: 'com.github.plokhotnyuk.jsoniter-scala', name: 'jsoniter-scala-macros_2.13', version: jsoniterScalaVersion
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.27.3'
testImplementation group: 'org.apache.commons', name: 'commons-text', version: '1.13.0'
testImplementation group: 'org.junit-pioneer', name: 'junit-pioneer', version: '2.3.0'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitVersion
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion
}
// --- Test Data Preparation ---
def testdataParent = layout.projectDirectory.dir("testdata")
def repoDir = testdataParent.dir("parse-number-fxx-test-data")
tasks.register('prepareTestDataDir') {
description = 'Create testdata/ directory if missing'
doLast {
def parent = testdataParent.asFile
if (!parent.exists()) {
logger.lifecycle("Creating ${parent}")
parent.mkdirs()
}
}
}
tasks.register('downloadTestData', Exec) {
description = 'Clone parse-number-fxx-test-data into testdata/ if missing'
group = 'verification'
dependsOn tasks.named('prepareTestDataDir')
// Run if repo dir missing OR empty (handles half-created directories)
onlyIf {
def d = repoDir.asFile
!d.exists() || (d.isDirectory() && (d.listFiles() == null || d.listFiles().length == 0))
}
workingDir testdataParent.asFile
commandLine 'git', 'clone', 'https://github.com/nigeltao/parse-number-fxx-test-data.git', 'parse-number-fxx-test-data'
doFirst {
logger.lifecycle("Cloning parse-number-fxx-test-data into ${repoDir.asFile}")
}
}
// Configuration common to ALL Test tasks (including 'test', 'test256', 'test512')
tasks.withType(Test).configureEach {
dependsOn tasks.named('downloadTestData')
// Fix: Ensure logging is visible in the console
testLogging {
showStandardStreams = true
events 'PASSED', 'SKIPPED', 'FAILED', 'STANDARD_OUT', 'STANDARD_ERROR'
exceptionFormat = 'full'
showExceptions = true
showCauses = true
showStackTraces = true
}
}
// --- Test Variants (256/512) ---
test {
useJUnitPlatform()
jvmArgs += [
'--add-modules', 'jdk.incubator.vector', '-Xmx2g'
]
failOnNoDiscoveredTests = false
}
// Generate test tasks for specific species (256, 512)
[256, 512].each { species ->
tasks.register("test${species}", Test) {
group = 'verification'
description = "Runs tests with org.simdjson.species=${species}"
// Fix: Removed 'dependsOn test'. This allows test256 to run independently.
// We use mustRunAfter so they don't interleave output if run together via 'check'.
dependsOn tasks.named('test')
useJUnitPlatform()
jvmArgs += [
'--add-modules', 'jdk.incubator.vector',
'-Xmx2g',
"-Dorg.simdjson.species=${species}"
]
}
}
tasks.named('check') {
dependsOn tasks.named('test256')
dependsOn tasks.named('test512')
}
tasks.withType(JmhBytecodeGeneratorTask).configureEach {
jvmArgs.set(["--add-modules=jdk.incubator.vector"])
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.add("--add-modules=jdk.incubator.vector")
}
tasks.compileJmhScala.classpath = sourceSets.main.compileClasspath
tasks.compileJmhJava.classpath += files(sourceSets.jmh.scala.classesDirectory)
compileTestJava {
options.compilerArgs += [
'--add-modules', 'jdk.incubator.vector'
]
}
javadoc.options {
addStringOption('-add-modules', 'jdk.incubator.vector')
}
jmh {
fork = 1
warmupIterations = 3
iterations = 5
jvmArgsPrepend = [
'--add-modules=jdk.incubator.vector'
]
if (OperatingSystem.current().isLinux()) {
def profilerList = []
if (getBooleanProperty('jmh.asyncProfilerEnabled', false)) {
createDirIfDoesNotExist('./profilers/async')
profilerList += ['async:verbose=true;output=flamegraph;event=cpu;dir=./profilers/async;libPath=' + getLibPath('LD_LIBRARY_PATH')]
}
if (getBooleanProperty('jmh.perfAsmEnabled', false)) {
createDirIfDoesNotExist('./profilers/perfasm')
profilerList += ['perfasm:intelSyntax=true;saveLog=true;saveLogTo=./profilers/perfasm']
}
if (getBooleanProperty('jmh.perfEnabled', false)) {
profilerList += ['perf']
}
profilers = profilerList
}
if (project.hasProperty('jmh.includes')) {
includes = [project.findProperty('jmh.includes')]
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from(components.java)
pom {
name = project.name
description = 'A Java version of simdjson, a high-performance JSON parser utilizing SIMD instructions.'
url = 'https://github.com/simdjson/simdjson-java'
issueManagement {
system = 'GitHub Issue Tracking'
url = 'https://github.com/simdjson/simdjson-java/issues'
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'piotrrzysko'
name = 'Piotr Rżysko'
email = 'piotr.rzysko@gmail.com'
}
}
scm {
url = 'https://github.com/simdjson/simdjson-java'
connection = 'scm:git@github.com:simdjson/simdjson-java.git'
developerConnection = 'scm:git@github.com:simdjson/simdjson-java.git'
}
}
}
}
}
if (System.getenv('GPG_KEY_ID')) {
signing {
useInMemoryPgpKeys(
System.getenv('GPG_KEY_ID'),
System.getenv('GPG_PRIVATE_KEY'),
System.getenv('GPG_PRIVATE_KEY_PASSWORD')
)
sign publishing.publications.mavenJava
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
if (System.getenv('SONATYPE_USERNAME')) {
username.set(System.getenv('SONATYPE_USERNAME'))
}
if (System.getenv('SONATYPE_PASSWORD')) {
password.set(System.getenv('SONATYPE_PASSWORD'))
}
stagingProfileId.set('3c0bbfe420699e')
}
}
connectTimeout.set(Duration.ofMinutes(3))
clientTimeout.set(Duration.ofMinutes(3))
}
def getBooleanProperty(String name, boolean defaultValue) {
Boolean.valueOf((project.findProperty(name) ?: defaultValue) as String)
}
static def getLibPath(String envVarName) {
System.getenv(envVarName) ?: System.getProperty('java.library.path')
}
static createDirIfDoesNotExist(String dir) {
File file = new File(dir)
file.mkdirs()
}