elastic/elasticsearch · error · GradleException

Can't write resource `${resourcePath}` to ${destination}

Error message

Can't write resource `${resourcePath}` to ${destination}

What it means

Thrown by ExportElasticsearchBuildResourcesTask.doExport when Files.copy of the resource stream to the destination fails with IOException. The resource was found on the classpath but writing it to outputDir/<destName> failed.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ExportElasticsearchBuildResourcesTask.java:113

    @TaskAction
    public void doExport() {
        if (resources.isEmpty()) {
            setDidWork(false);
            throw new StopExecutionException();
        }
        resources.entrySet().stream().parallel().forEach(entry -> {
            String resourcePath = entry.getKey();
            String destName = entry.getValue();
            Path destination = outputDir.get().file(destName).getAsFile().toPath();
            try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
                Files.createDirectories(destination.getParent());
                if (is == null) {
                    throw new GradleException("Can't export `" + resourcePath + "` from build-tools: not found");
                }
                Files.copy(is, destination, StandardCopyOption.REPLACE_EXISTING);
            } catch (IOException e) {
                throw new GradleException("Can't write resource `" + resourcePath + "` to " + destination, e);
            }
        });
    }

}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Check write permissions and free disk space on the output directory.
  2. Ensure the output directory is not on a read-only filesystem.
  3. Close any process locking the destination file (IDE, antivirus, prior build).
  4. Point Gradle's build output to a writable location.
Defensive patterns

Strategy: try-catch

Validate before calling

Path dest = outputDir.get().file(destName).getAsFile().toPath();
if (Files.isWritable(dest.getParent()) == false) {
    throw new GradleException("Output directory not writable: " + dest.getParent());
}

Try / catch

try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
    Files.copy(is, destination, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
    throw new GradleException("Can't write resource `" + resourcePath + "` to " + destination, e);
}

Prevention

When it happens

Trigger: The destination directory is read-only, the disk is full, the parent cannot be created, or the destination is locked by another process when Files.copy runs.

Common situations: Output directory on a read-only mount; disk exhaustion; antivirus/file lock on Windows; permission denied on the build output tree.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/57b5e71f0e10df68. Report an issue: GitHub.