elastic/elasticsearch · error · GradleException
Unsupported classpath element: {}
Error message
Unsupported classpath element: {} What it means
Thrown by SplitPackagesAuditTask.readPackages when a classpath element passed to the audit is neither a filesystem directory nor a file ending in .jar. The method only handles directories and jars; any other artifact type (e.g. a .zip, .class, or symbolic link to neither) falls into the else branch and aborts.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/SplitPackagesAuditTask.java:313
}
}
// TODO: want to read packages the same for src dirs and jars, but src dirs we also want the files in the src package dir
private static Set<String> readPackages(File classpathElement) {
Set<String> packages = new HashSet<>();
Consumer<Path> addClassPackage = p -> packages.add(getPackageName(p));
try {
if (classpathElement.isDirectory()) {
walkJavaFiles(classpathElement.toPath(), ".class", addClassPackage);
} else if (classpathElement.getName().endsWith(".jar")) {
try (FileSystem jar = FileSystems.newFileSystem(classpathElement.toPath(), Map.of())) {
for (Path root : jar.getRootDirectories()) {
walkJavaFiles(root, ".class", addClassPackage);
}
}
} else {
throw new GradleException("Unsupported classpath element: " + classpathElement);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return packages;
}
private static void walkJavaFiles(Path root, String suffix, Consumer<Path> classConsumer) throws IOException {
if (Files.exists(root) == false) {
return;
}
try (var paths = Files.walk(root)) {
paths.filter(p -> p.toString().endsWith(suffix))
.map(root::relativize)
.filter(p -> p.getNameCount() > 1) // module-info or other things without a package can be skipped
.filter(p -> p.toString().startsWith("META-INF") == false)
.forEach(classConsumer);View on GitHub (pinned to db6a809a66)
Solutions
- Inspect the Gradle dependency graph for the failing project (./gradlew :<project>:dependencies) and find which dependency resolves to a non-jar, non-directory artifact.
- Exclude or correct the offending dependency/configuration so the audit only sees directories and .jar files.
- If a legitimate non-jar archive must be audited, extend readPackages to handle that extension, but first verify the artifact is genuinely required on the classpath.
- Clear the Gradle cache for the suspect artifact (rm -rf ~/.gradle/caches/modules-2/...) and re-resolve to rule out cache corruption.
Defensive patterns
Strategy: validation
Validate before calling
// Validate classpath elements before passing them to the audit
for (File f : classpathElements) {
if (f.isDirectory() == false && f.getName().endsWith(".jar") == false) {
throw new IllegalArgumentException("Unsupported classpath element for audit: " + f);
}
} Try / catch
try { Set<String> pkgs = SplitPackagesAuditTask.readPackages(element); }
catch (GradleException e) {
if (e.getMessage().startsWith("Unsupported classpath element")) { /* log + skip or fix config */ }
else throw e;
} Prevention
- Restrict audit inputs to project outputs and resolved jar dependencies only.
- Run ./gradlew :<project>:dependencies to confirm artifact types before wiring custom configurations.
- Avoid passing resource bundles, zips, or raw .class files into the audit classpath.
When it happens
Trigger: The audit receives a File classpathElement that is not a directory and whose name does not end with .jar — for example a raw .class file, a .zip archive, or an unresolved/pom artifact. This typically happens when a project dependency resolves to an unexpected artifact type or when a custom configuration feeds non-jar entries into the audit.
Common situations: Adding a dependency that resolves to a zip-based or unpacked artifact; a corrupted/incomplete Gradle dependency cache producing a non-jar file; a custom classpath configuration mistakenly including resource bundles or individual class files; Gradle version change altering how artifacts are materialized.
Related errors
- Build directory unknown to gradle: {}
- error patching [%s]: the jar does not contain [%s]
- Missing 'classesDirs' or 'classpath' property.
- Failed to build classpath URLs.
- Unknown license for license file: {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/b6a367f0c8f550c8.
Report an issue: GitHub.