@@ -28,17 +28,52 @@ repositories {
2828 mavenCentral()
2929}
3030
31+ // Dynamically resolve Java major version from:
32+ // 1) env BUILD_JAVA_VERSION (if set), else
33+ // 2) the JVM running Gradle (JavaVersion.current().majorVersion)
34+ //
35+ // Accepts values like: "24", "24.0.1", "24-ea", "24.0.2-tem", etc.
36+ static int resolveBuildJavaVersion () {
37+ String v = System . getenv(' BUILD_JAVA_VERSION' ) ?: JavaVersion . current(). majorVersion
38+
39+ int dot = v. indexOf(' .' )
40+ if (dot >= 0 ) {
41+ v = v. substring(0 , dot)
42+ }
43+
44+ int dash = v. indexOf(' -' )
45+ if (dash >= 0 ) {
46+ v = v. substring(0 , dash)
47+ }
48+
49+ try {
50+ return Integer . parseInt(v)
51+ } catch (Exception e) {
52+ throw new GradleException (" Invalid BUILD_JAVA_VERSION '${ System.getenv('BUILD_JAVA_VERSION')} '. " +
53+ " Expected a Java major version like '24' (optionally with suffixes like '24.0.1' or '24-ea')." , e)
54+ }
55+ }
56+
57+ // Usage
58+ def buildJavaVersion = resolveBuildJavaVersion()
59+
60+ // recommended build java version is 25
61+ if (buildJavaVersion < 24 ) {
62+ throw new GradleException (
63+ " This build requires Java 24+.\n " +
64+ " Detected buildJavaVersion=${ buildJavaVersion} .\n " +
65+ " Either run Gradle with JDK 24+ (JAVA_HOME / PATH), or set BUILD_JAVA_VERSION=24 (or higher)."
66+ )
67+ }
68+
3169java {
32- // It seems that specifying the minimum supported Java version while allowing the use of newer
33- // ones isn't possible in Gradle. To test the library against multiple Java versions, the
34- // workaround proposed in https://github.com/gradle/gradle/issues/16256 has been applied:
35- if (! JavaVersion . current(). isCompatibleWith(JavaVersion . VERSION_24 )) {
36- toolchain {
37- languageVersion = JavaLanguageVersion . of(24 )
38- }
70+ toolchain {
71+ languageVersion = JavaLanguageVersion . of(buildJavaVersion)
3972 }
4073 withJavadocJar()
4174 withSourcesJar()
75+ sourceCompatibility = JavaVersion . toVersion(buildJavaVersion)
76+ targetCompatibility = JavaVersion . toVersion(buildJavaVersion)
4277}
4378
4479ext {
@@ -99,7 +134,9 @@ tasks.withType(Test).configureEach {
99134}
100135
101136tasks. register(' test256' , Test ) {
102- dependsOn downloadTestData
137+ // IMPORTANT: run the normal test task first (no cycles)
138+ dependsOn tasks. named(' test' )
139+
103140 useJUnitPlatform()
104141 jvmArgs + = [
105142 ' --add-modules' , ' jdk.incubator.vector' ,
@@ -112,7 +149,9 @@ tasks.register('test256', Test) {
112149}
113150
114151tasks. register(' test512' , Test ) {
115- dependsOn downloadTestData
152+ // IMPORTANT: run the normal test task first (no cycles)
153+ dependsOn tasks. named(' test' )
154+
116155 useJUnitPlatform()
117156 jvmArgs + = [
118157 ' --add-modules' , ' jdk.incubator.vector' ,
@@ -131,14 +170,17 @@ test {
131170 jvmArgs + = [
132171 ' --add-modules' , ' jdk.incubator.vector' , ' -Xmx2g'
133172 ]
134- // still run the vector-width-specific tasks first
135- dependsOn ' test256'
136- dependsOn ' test512'
137173
138- // and don 't blow up if this particular task finds nothing
174+ // Don 't blow up if this particular task finds nothing
139175 failOnNoDiscoveredTests = false
140176}
141177
178+ // Recommended: `./gradlew check` runs all test variants
179+ tasks. named(' check' ) {
180+ dependsOn tasks. named(' test256' )
181+ dependsOn tasks. named(' test512' )
182+ }
183+
142184tasks. withType(JmhBytecodeGeneratorTask ). configureEach {
143185 jvmArgs. set([" --add-modules=jdk.incubator.vector" ])
144186}
0 commit comments