Method to check if GraalVM JDK Distribution

Method to check if you are running in GraalVM JDK distribution. I have used it often in Gradle build files to decide whether a Gradle task should be enabled.

private static boolean isGraalVMJava() {
    return
        (System.getProperty("java.home") != null && java.nio.file.Files.exists(java.nio.file.Paths.get("${System.getProperty("java.home")}/lib/graalvm")))
        || Arrays.asList("jvmci.Compiler", "java.vendor.version", "java.vendor")
            .stream()
            .anyMatch(propertyName -> {
                String value = System.getProperty(propertyName);
                return value != null && value.toLowerCase(Locale.ENGLISH).contains("graal");
            });
}

Tags: #java #graalvm #gradle
Sep 2023, 21.

 

My next events:
🗓 Nov 22 09:00 JCON World Micronaut CRaC
🗓 Nov 23 15:00 JCON World Micronaut EclipseStore