11import me.champeau.jmh.JmhBytecodeGeneratorTask
2- import org.ajoberstar.grgit.Grgit
32import org.gradle.internal.os.OperatingSystem
43
54import java.time.Duration
@@ -8,17 +7,16 @@ plugins {
87 id ' java'
98 id ' scala'
109 id ' me.champeau.jmh' version ' 0.7.1'
11- id ' org.ajoberstar.grgit' version ' 5.2.0'
12- id ' pl.allegro.tech.build.axion-release' version ' 1.15.5'
13- id ' io.github.gradle-nexus.publish-plugin' version ' 1.3.0'
10+ id ' pl.allegro.tech.build.axion-release' version ' 1.21.1'
11+ id ' io.github.gradle-nexus.publish-plugin' version ' 2.0.0'
1412 id ' maven-publish'
1513 id ' signing'
1614}
1715
1816scmVersion {
1917 versionCreator(' versionWithBranch' )
2018 tag {
21- prefix = ' '
19+ prefix. set( ' ' )
2220 }
2321}
2422
@@ -29,17 +27,46 @@ repositories {
2927 mavenCentral()
3028}
3129
30+ // --- Java Version Resolution ---
31+ static int resolveBuildJavaVersion () {
32+ String v = System . getenv(' BUILD_JAVA_VERSION' ) ?: JavaVersion . current(). majorVersion
33+
34+ int dot = v. indexOf(' .' )
35+ if (dot >= 0 ) {
36+ v = v. substring(0 , dot)
37+ }
38+
39+ int dash = v. indexOf(' -' )
40+ if (dash >= 0 ) {
41+ v = v. substring(0 , dash)
42+ }
43+
44+ try {
45+ return Integer . parseInt(v)
46+ } catch (Exception e) {
47+ throw new GradleException (" Invalid BUILD_JAVA_VERSION '${ System.getenv('BUILD_JAVA_VERSION')} '. " +
48+ " Expected a Java major version like '24' (optionally with suffixes like '24.0.1' or '24-ea')." , e)
49+ }
50+ }
51+
52+ def buildJavaVersion = resolveBuildJavaVersion()
53+
54+ if (buildJavaVersion < 24 ) {
55+ throw new GradleException (
56+ " This build requires Java 24+.\n " +
57+ " Detected buildJavaVersion=${ buildJavaVersion} .\n " +
58+ " Either run Gradle with JDK 24+ (JAVA_HOME / PATH), or set BUILD_JAVA_VERSION=24 (or higher)."
59+ )
60+ }
61+
3262java {
33- // It seems that specifying the minimum supported Java version while allowing the use of newer
34- // ones isn't possible in Gradle. To test the library against multiple Java versions, the
35- // workaround proposed in https://github.com/gradle/gradle/issues/16256 has been applied:
36- if (! JavaVersion . current(). isCompatibleWith(JavaVersion . VERSION_24 )) {
37- toolchain {
38- languageVersion = JavaLanguageVersion . of(24 )
39- }
63+ toolchain {
64+ languageVersion = JavaLanguageVersion . of(buildJavaVersion)
4065 }
4166 withJavadocJar()
4267 withSourcesJar()
68+ sourceCompatibility = JavaVersion . toVersion(buildJavaVersion)
69+ targetCompatibility = JavaVersion . toVersion(buildJavaVersion)
4370}
4471
4572ext {
@@ -62,49 +89,86 @@ dependencies {
6289 testRuntimeOnly group : ' org.junit.jupiter' , name : ' junit-jupiter-engine' , version : junitVersion
6390}
6491
65- tasks. register(' downloadTestData' ) {
66- doFirst {
67- def testDataDir = new File (" ${ project.projectDir.getAbsolutePath()} /testdata" )
68- if (! testDataDir. exists()) {
69- testDataDir. mkdir()
70- }
71- def numbersTestDataDir = new File (" ${ testDataDir} /parse-number-fxx-test-data" )
72- if (! numbersTestDataDir. exists()) {
73- def grgit = Grgit . clone(dir : numbersTestDataDir, uri : ' https://github.com/nigeltao/parse-number-fxx-test-data.git' )
74- grgit. close()
92+ // --- Test Data Preparation ---
93+ def testdataParent = layout. projectDirectory. dir(" testdata" )
94+ def repoDir = testdataParent. dir(" parse-number-fxx-test-data" )
95+
96+ tasks. register(' prepareTestDataDir' ) {
97+ description = ' Create testdata/ directory if missing'
98+ doLast {
99+ def parent = testdataParent. asFile
100+ if (! parent. exists()) {
101+ logger. lifecycle(" Creating ${ parent} " )
102+ parent. mkdirs()
75103 }
76104 }
77105}
78106
79- tasks. register(' test256' , Test ) {
80- dependsOn downloadTestData
81- useJUnitPlatform()
82- jvmArgs + = [
83- ' --add-modules' , ' jdk.incubator.vector' ,
84- ' -Xmx2g' ,
85- ' -Dorg.simdjson.species=256'
86- ]
107+ tasks. register(' downloadTestData' , Exec ) {
108+ description = ' Clone parse-number-fxx-test-data into testdata/ if missing'
109+ group = ' verification'
110+ dependsOn tasks. named(' prepareTestDataDir' )
111+
112+ // Run if repo dir missing OR empty (handles half-created directories)
113+ onlyIf {
114+ def d = repoDir. asFile
115+ ! d. exists() || (d. isDirectory() && (d. listFiles() == null || d. listFiles(). length == 0 ))
116+ }
117+
118+ workingDir testdataParent. asFile
119+ commandLine ' git' , ' clone' , ' https://github.com/nigeltao/parse-number-fxx-test-data.git' , ' parse-number-fxx-test-data'
120+
121+ doFirst {
122+ logger. lifecycle(" Cloning parse-number-fxx-test-data into ${ repoDir.asFile} " )
123+ }
124+ }
125+
126+ // Configuration common to ALL Test tasks (including 'test', 'test256', 'test512')
127+ tasks. withType(Test ). configureEach {
128+ dependsOn tasks. named(' downloadTestData' )
129+
130+ // Fix: Ensure logging is visible in the console
87131 testLogging {
132+ showStandardStreams = true
88133 events ' PASSED' , ' SKIPPED' , ' FAILED' , ' STANDARD_OUT' , ' STANDARD_ERROR'
134+ exceptionFormat = ' full'
135+ showExceptions = true
136+ showCauses = true
137+ showStackTraces = true
89138 }
90139}
91140
92- tasks . register( ' test512 ' , Test ) {
93- dependsOn downloadTestData
141+ // --- Test Variants (256/512) ---
142+ test {
94143 useJUnitPlatform()
95144 jvmArgs + = [
96- ' --add-modules' , ' jdk.incubator.vector' ,
97- ' -Xmx2g' ,
98- ' -Dorg.simdjson.species=512'
145+ ' --add-modules' , ' jdk.incubator.vector' , ' -Xmx2g'
99146 ]
100- testLogging {
101- events ' PASSED' , ' SKIPPED' , ' FAILED' , ' STANDARD_OUT' , ' STANDARD_ERROR'
147+ failOnNoDiscoveredTests = false
148+ }
149+
150+ // Generate test tasks for specific species (256, 512)
151+ [256 , 512 ]. each { species ->
152+ tasks. register(" test${ species} " , Test ) {
153+ group = ' verification'
154+ description = " Runs tests with org.simdjson.species=${ species} "
155+
156+ // Fix: Removed 'dependsOn test'. This allows test256 to run independently.
157+ // We use mustRunAfter so they don't interleave output if run together via 'check'.
158+ dependsOn tasks. named(' test' )
159+
160+ useJUnitPlatform()
161+ jvmArgs + = [
162+ ' --add-modules' , ' jdk.incubator.vector' ,
163+ ' -Xmx2g' ,
164+ " -Dorg.simdjson.species=${ species} "
165+ ]
102166 }
103167}
104168
105- test {
106- dependsOn ' test256'
107- dependsOn ' test512'
169+ tasks . named( ' check ' ) {
170+ dependsOn tasks . named( ' test256' )
171+ dependsOn tasks . named( ' test512' )
108172}
109173
110174tasks. withType(JmhBytecodeGeneratorTask ). configureEach {
@@ -116,7 +180,6 @@ tasks.withType(JavaCompile).configureEach {
116180}
117181
118182tasks. compileJmhScala. classpath = sourceSets. main. compileClasspath
119-
120183tasks. compileJmhJava. classpath + = files(sourceSets. jmh. scala. classesDirectory)
121184
122185compileTestJava {
@@ -206,15 +269,21 @@ if (System.getenv('GPG_KEY_ID')) {
206269nexusPublishing {
207270 repositories {
208271 sonatype {
209- nexusUrl = uri(" https://ossrh-staging-api.central.sonatype.com/service/local/" )
210- snapshotRepositoryUrl = uri(" https://central.sonatype.com/repository/maven-snapshots/" )
211- stagingProfileId = ' 3c0bbfe420699e'
212- username = System . getenv(' SONATYPE_USERNAME' )
213- password = System . getenv(' SONATYPE_PASSWORD' )
272+ nexusUrl. set(uri(" https://ossrh-staging-api.central.sonatype.com/service/local/" ))
273+ snapshotRepositoryUrl. set(uri(" https://central.sonatype.com/repository/maven-snapshots/" ))
274+
275+ if (System . getenv(' SONATYPE_USERNAME' )) {
276+ username. set(System . getenv(' SONATYPE_USERNAME' ))
277+ }
278+ if (System . getenv(' SONATYPE_PASSWORD' )) {
279+ password. set(System . getenv(' SONATYPE_PASSWORD' ))
280+ }
281+
282+ stagingProfileId. set(' 3c0bbfe420699e' )
214283 }
215284 }
216- connectTimeout = Duration . ofMinutes(3 )
217- clientTimeout = Duration . ofMinutes(3 )
285+ connectTimeout. set( Duration . ofMinutes(3 ) )
286+ clientTimeout. set( Duration . ofMinutes(3 ) )
218287}
219288
220289def getBooleanProperty (String name , boolean defaultValue ) {
0 commit comments