{"record":{"id":"feace50d96793606","repo":"elastic/elasticsearch","slug":"jvm-metadata-cannot-be-resolved-for","errorCode":null,"errorMessage":"Jvm Metadata cannot be resolved for {}","messagePattern":"Jvm Metadata cannot be resolved for (.+?)","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java","lineNumber":492,"sourceCode":"\n            return b.toString();\n        } catch (IOException e) {\n            throw new UncheckedIOException(\"Error trying to read classpath resource: \" + resourcePath, e);\n        }\n    }\n\n    private static class ErrorTraceMetadataDetector implements JvmMetadataDetector {\n        private final JvmMetadataDetector delegate;\n\n        ErrorTraceMetadataDetector(JvmMetadataDetector delegate) {\n            this.delegate = delegate;\n        }\n\n        @Override\n        public JvmInstallationMetadata getMetadata(InstallationLocation installationLocation) {\n            JvmInstallationMetadata metadata = delegate.getMetadata(installationLocation);\n            if (metadata instanceof JvmInstallationMetadata.FailureInstallationMetadata) {\n                throw new GradleException(\"Jvm Metadata cannot be resolved for \" + metadata.getJavaHome().toString());\n            }\n            return metadata;\n        }\n    }\n\n    private static class MetadataBasedToolChainMatcher implements Action<JavaToolchainSpec> {\n        private final JvmVendorSpec expectedVendorSpec;\n        private final JavaLanguageVersion expectedJavaLanguageVersion;\n\n        MetadataBasedToolChainMatcher(JvmInstallationMetadata metadata) {\n            expectedVendorSpec = JvmVendorSpec.matching(metadata.getVendor().getRawVendor());\n            expectedJavaLanguageVersion = JavaLanguageVersion.of(metadata.getLanguageVersion().getMajorVersion());\n        }\n\n        @Override\n        public void execute(JavaToolchainSpec spec) {\n            spec.getVendor().set(expectedVendorSpec);\n            spec.getLanguageVersion().set(expectedJavaLanguageVersion);","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java#L474-L510","documentation":"Thrown by ErrorTraceMetadataDetector, a decorator around Gradle's JvmMetadataDetector that converts silent failures into hard build errors. When Gradle probes a candidate JAVA_HOME and the probe returns a FailureInstallationMetadata (the JVM could not be inspected), this detector throws a GradleException instead of letting the toolchain fall through to another JVM. It exists so the build fails loudly on an unusable JDK rather than silently picking a wrong one.","triggerScenarios":"Triggered when the Java toolchain resolution calls getMetadata on an InstallationLocation whose delegate returns FailureInstallationMetadata — i.e., the pointed-to javaHome exists but is not a valid/complete JDK (missing release file, broken java executable, wrong arch, or a JRE rather than a JDK).","commonSituations":"JAVA_HOME pointing at a stripped/partial JDK install; a JDK auto-provisioned by Gradle that got corrupted mid-download; switching JDK distribution with a stale JAVA_HOME; a CI image shipping only a JRE; a macOS .jdk bundle whose Contents/Home was altered; toolchain.vendor/version constraints that no installed JVM satisfies.","solutions":["Verify the JDK is complete: run $JAVA_HOME/bin/java -version and $JAVA_HOME/bin/javac -version; both must succeed.","Point JAVA_HOME at a fresh full JDK install matching the project's required version (JDK 25 for this repo).","Run ./gradlew -q javaToolchains to list every detected JVM and confirm the intended one is recognised with valid metadata.","If using Gradle auto-provisioning, clear the toolchain cache (~/.gradle/jdks) and let it re-download.","Loosen or correct the toolchain vendor/version spec in build-conventions if it excludes the only available JDK."],"exampleFix":"// before: JAVA_HOME=/opt/jre-21 (JRE only, no javac)\n// after:  export JAVA_HOME=/opt/jdk-25; java -version && javac -version","handlingStrategy":"validation","validationCode":"// Validate the candidate JAVA_HOME before letting the build resolve the toolchain\nFile javaHome = new File(System.getenv(\"JAVA_HOME\"));\nFile javaBin  = new File(javaHome, \"bin/java\" + (System.getProperty(\"os.name\").startsWith(\"Windows\") ? \".exe\" : \"\"));\nFile javacBin = new File(javaHome, \"bin/javac\" + (System.getProperty(\"os.name\").startsWith(\"Windows\") ? \".exe\" : \"\"));\nif (!javaBin.isFile() || !javacBin.isFile()) {\n    throw new IllegalStateException(\"JAVA_HOME does not point to a complete JDK: \" + javaHome);\n}\nFile release = new File(javaHome, \"release\");\nif (!release.isFile()) {\n    throw new IllegalStateException(\"Not a JDK home (no 'release' file): \" + javaHome);\n}","typeGuard":null,"tryCatchPattern":"// Global build-init guard\ntry {\n    project.getExtensions().getByType(JavaPluginExtension.class).getToolchain();\n} catch (GradleException e) {\n    if (e.getMessage().contains(\"Jvm Metadata cannot be resolved\")) {\n        throw new GradleException(\"Toolchain JDK unusable. Run `./gradlew -q javaToolchains` and fix JAVA_HOME.\", e);\n    }\n    throw e;\n}","preventionTips":["Pin JAVA_HOME to a full JDK (not a JRE) matching the project's required version.","Document the required JDK version in BUILDING.md and CI setup scripts.","In CI, install JDKs via a toolchain manager (sdkman/asdf) that guarantees a complete install.","Run `./gradlew -q javaToolchains` in onboarding to confirm detection."],"tags":["gradle","toolchain","jdk","build-setup","jvm-metadata"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}