elastic/elasticsearch · error · IllegalStateException
Could not create output directory: {parent}
Error message
Could not create output directory: {parent} What it means
Thrown by AugmentForeignModuleInfoTask.augment() when the parent directory of the configured output module-info file cannot be created. The task runs ModuleInfoAugmenter as an external Java process to process module-info.java files. Before launching the process, it ensures the output directory exists via mkdirs(). The guard checks parent != null, mkdirs() == false, and isDirectory() == false.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/foreign/AugmentForeignModuleInfoTask.java:68
@InputFile
@PathSensitive(PathSensitivity.NAME_ONLY)
public abstract RegularFileProperty getServicesFile();
@Classpath
public abstract ConfigurableFileCollection getAugmenterClasspath();
@Nested
public abstract Property<JavaLauncher> getJavaLauncher();
@OutputFile
public abstract RegularFileProperty getOutputModuleInfo();
@TaskAction
public void augment() {
File outputFile = getOutputModuleInfo().get().getAsFile();
File parent = outputFile.getParentFile();
if (parent != null && parent.mkdirs() == false && parent.isDirectory() == false) {
throw new IllegalStateException("Could not create output directory: " + parent);
}
String javaExecutable = getJavaLauncher().get().getExecutablePath().getAsFile().getAbsolutePath();
execOperations.exec(spec -> {
spec.executable(javaExecutable);
spec.args("-cp", getAugmenterClasspath().getAsPath());
spec.args("org.elasticsearch.foreign.processor.ModuleInfoAugmenter");
spec.args(
getInputModuleInfo().get().getAsFile().getAbsolutePath(),
getServicesFile().get().getAsFile().getAbsolutePath(),
outputFile.getAbsolutePath()
);
}).assertNormalExitValue();
}
}
View on GitHub (pinned to db6a809a66)
Solutions
- Run ./gradlew clean to remove any stale files conflicting with the expected directory path.
- Verify the output module-info path is set to a location within the build directory.
- Ensure the Gradle daemon has write permissions to the parent path.
- Check for path conflicts: ls -la on the parent path to confirm no regular file occupies the directory slot.
Defensive patterns
Strategy: validation
Validate before calling
// Validate output path before task
File parent = outputFile.getParentFile();
if (parent != null && parent.exists() && !parent.isDirectory()) {
throw new GradleException("Output parent exists as a non-directory file: " + parent);
} Prevention
- Configure the output module-info path within the build directory.
- Run ./gradlew clean to clear stale file/directory conflicts.
- Ensure write permissions on the build directory.
When it happens
Trigger: The output file's parent directory does not exist, mkdirs() returns false (because of a conflicting file, permissions, or read-only filesystem), and isDirectory() returns false. The three-condition guard avoids throwing when mkdirs() returns false because the directory already existed (a benign race or pre-existing directory).
Common situations: The OutputModuleInfo property is configured to a path whose parent is a regular file. The build directory is read-only. The output path resolves outside the project (e.g., a typo in the configuration). A stale file occupies the path where a directory is expected.
Related errors
- Failed to create output directory: {outputDir}
- Could not create directory: {packageDir}
- Unable to create reaper JAR output directory {}
- Failed to write unicast_hosts for {}
- Failed to create working directory for {}, with: {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/29cd7a290637132d.
Report an issue: GitHub.