Skip to content

Commit 6cf467f

Browse files
authored
ThirdPartyAuditTask - Add vector module when building with JDK 21 (elastic#96949)
This commit extends the ThirdPartyAuditTask check that adds the vector module when building, to include JDK 21. This is needed now as Lucene has added support for the VectorUtilPanamaProvider with JDK 21. We want to keep the check to very specific versions / ranges, that match that of Lucene.
1 parent 8d6b339 commit 6cf467f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTask.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import javax.inject.Inject;
5959

6060
import static org.gradle.api.JavaVersion.VERSION_20;
61+
import static org.gradle.api.JavaVersion.VERSION_21;
6162

6263
@CacheableTask
6364
public abstract class ThirdPartyAuditTask extends DefaultTask {
@@ -337,8 +338,8 @@ private String runForbiddenAPIsCli() throws IOException {
337338
spec.setExecutable(javaHome.get() + "/bin/java");
338339
}
339340
spec.classpath(getForbiddenAPIsClasspath(), classpath);
340-
// Enable explicitly for each release as appropriate. Just JDK 20 for now, and just the vector module.
341-
if (isJava20()) {
341+
// Enable explicitly for each release as appropriate. Just JDK 20/21 for now, and just the vector module.
342+
if (isJavaVersion(VERSION_20) || isJavaVersion(VERSION_21)) {
342343
spec.jvmArgs("--add-modules", "jdk.incubator.vector");
343344
}
344345
spec.jvmArgs("-Xmx1g");
@@ -363,13 +364,13 @@ private String runForbiddenAPIsCli() throws IOException {
363364
return forbiddenApisOutput;
364365
}
365366

366-
/** Returns true iff the Java version is 20. */
367-
private boolean isJava20() {
367+
/** Returns true iff the build Java version is the same as the given version. */
368+
private boolean isJavaVersion(JavaVersion version) {
368369
if (BuildParams.getIsRuntimeJavaHomeSet()) {
369-
if (VERSION_20.equals(BuildParams.getRuntimeJavaVersion())) {
370+
if (version.equals(BuildParams.getRuntimeJavaVersion())) {
370371
return true;
371372
}
372-
} else if ("20".equals(VersionProperties.getBundledJdkMajorVersion())) {
373+
} else if (version.getMajorVersion().equals(VersionProperties.getBundledJdkMajorVersion())) {
373374
return true;
374375
}
375376
return false;

0 commit comments

Comments
 (0)