{"record":{"id":"0029a340530907da","repo":"elastic/elasticsearch","slug":"build-directory-unknown-to-gradle","errorCode":null,"errorMessage":"Build directory unknown to gradle: {}","messagePattern":"Build directory unknown to gradle: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/SplitPackagesAuditTask.java","lineNumber":350,"sourceCode":"            }\n        }\n\n        private static String getPackageName(Path path) {\n            List<String> subpackages = new ArrayList<>();\n            for (int i = 0; i < path.getNameCount() - 1; ++i) {\n                subpackages.add(path.getName(i).toString());\n            }\n            return String.join(\".\", subpackages);\n        }\n\n        private String formatDependency(File dependencyFile) {\n            if (dependencyFile.isDirectory()) {\n                while (dependencyFile.getName().equals(\"build\") == false) {\n                    dependencyFile = dependencyFile.getParentFile();\n                }\n                String projectName = getParameters().getProjectBuildDirs().get().get(dependencyFile);\n                if (projectName == null) {\n                    throw new IllegalStateException(\"Build directory unknown to gradle: \" + dependencyFile);\n                }\n                return \"project \" + projectName;\n            }\n            return dependencyFile.getName(); // just the jar filename\n        }\n    }\n\n    interface Parameters extends WorkParameters {\n        Property<String> getProjectPath();\n\n        MapProperty<File, String> getProjectBuildDirs();\n\n        ConfigurableFileCollection getClasspath();\n\n        SetProperty<File> getSrcDirs();\n\n        SetProperty<String> getIgnoreClasses();\n","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/SplitPackagesAuditTask.java#L332-L368","documentation":"Thrown by SplitPackagesAuditTask.formatDependency while walking parent directories of a directory-valued dependency file looking for a directory literally named 'build'. Once found, it looks that build dir up in the projectBuildDirs map (File -> project path); if the map has no entry the lookup returns null and the task throws because it cannot attribute the dependency to a Gradle project.","triggerScenarios":"A dependency file is a directory (not a jar), so formatDependency walks up until it finds a parent named 'build', but that build directory was not registered in the task's projectBuildDirs parameter. This happens when a directory dependency lives outside the set of known project build outputs or under a 'build' folder that is not the canonical project build dir.","commonSituations":"A composite/included build whose build dir isn't passed to the audit's projectBuildDirs map; a directory dependency pointing at an external/unmanaged source tree that happens to contain a 'build' folder; cross-project classpath entries added via custom configurations that bypass the standard project output wiring.","solutions":["Verify the offending directory dependency is a legitimate Gradle project output; if so, ensure its build dir is included in getProjectBuildDirs() passed to the SplitPackagesAuditTask parameters.","If the directory is an external/non-project classpath root, convert it to a jar or exclude it from the audit input configuration.","Run with --debug and inspect the formatDependency call to see which directory triggered the null lookup, then trace it back to the configuration that supplied it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before running, ensure every directory dependency maps to a known project build dir\nMap<File,String> projectBuildDirs = parameters.getProjectBuildDirs().get();\nfor (File dep : directoryDependencies) {\n    File buildRoot = findAncestorNamed(dep, \"build\");\n    if (buildRoot == null || projectBuildDirs.containsKey(buildRoot) == false) {\n        throw new IllegalStateException(\"Directory dependency not registered: \" + dep);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep directory-valued classpath entries limited to standard Gradle project outputs.","When adding composite builds, wire their build dirs into the audit's projectBuildDirs parameter.","Avoid external source trees that coincidentally contain a 'build' folder."],"tags":["build","gradle","classpath","dependencies","configuration"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}