{"record":{"id":"b6a367f0c8f550c8","repo":"elastic/elasticsearch","slug":"unsupported-classpath-element","errorCode":null,"errorMessage":"Unsupported classpath element: {}","messagePattern":"Unsupported classpath element: (.+?)","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/SplitPackagesAuditTask.java","lineNumber":313,"sourceCode":"            }\n        }\n\n        // 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\n        private static Set<String> readPackages(File classpathElement) {\n            Set<String> packages = new HashSet<>();\n            Consumer<Path> addClassPackage = p -> packages.add(getPackageName(p));\n\n            try {\n                if (classpathElement.isDirectory()) {\n                    walkJavaFiles(classpathElement.toPath(), \".class\", addClassPackage);\n                } else if (classpathElement.getName().endsWith(\".jar\")) {\n                    try (FileSystem jar = FileSystems.newFileSystem(classpathElement.toPath(), Map.of())) {\n                        for (Path root : jar.getRootDirectories()) {\n                            walkJavaFiles(root, \".class\", addClassPackage);\n                        }\n                    }\n                } else {\n                    throw new GradleException(\"Unsupported classpath element: \" + classpathElement);\n                }\n            } catch (IOException e) {\n                throw new UncheckedIOException(e);\n            }\n\n            return packages;\n        }\n\n        private static void walkJavaFiles(Path root, String suffix, Consumer<Path> classConsumer) throws IOException {\n            if (Files.exists(root) == false) {\n                return;\n            }\n            try (var paths = Files.walk(root)) {\n                paths.filter(p -> p.toString().endsWith(suffix))\n                    .map(root::relativize)\n                    .filter(p -> p.getNameCount() > 1) // module-info or other things without a package can be skipped\n                    .filter(p -> p.toString().startsWith(\"META-INF\") == false)\n                    .forEach(classConsumer);","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/SplitPackagesAuditTask.java#L295-L331","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate classpath elements before passing them to the audit\nfor (File f : classpathElements) {\n    if (f.isDirectory() == false && f.getName().endsWith(\".jar\") == false) {\n        throw new IllegalArgumentException(\"Unsupported classpath element for audit: \" + f);\n    }\n}","typeGuard":null,"tryCatchPattern":"try { Set<String> pkgs = SplitPackagesAuditTask.readPackages(element); }\ncatch (GradleException e) {\n    if (e.getMessage().startsWith(\"Unsupported classpath element\")) { /* log + skip or fix config */ }\n    else throw e;\n}","preventionTips":["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."],"tags":["build","gradle","classpath","dependencies","precommit"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}