elastic/elasticsearch · error · GradleException
Can't export `${resourcePath}` from build-tools: not found
Error message
Can't export `${resourcePath}` from build-tools: not found What it means
Thrown by ExportElasticsearchBuildResourcesTask.doExport when getClass().getClassLoader().getResourceAsStream(resourcePath) returns null - the requested resource is not present on the build-tools classpath. The task exports classpath resources to an output directory at execution time.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ExportElasticsearchBuildResourcesTask.java:109
);
}
resources.put(resource, destName);
}
@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
- Verify the resource path exists under build-tools/src/main/resources.
- Remove any leading slash and match the exact case and extension.
- Rebuild the build-tools jar so the resource is packaged.
- If the resource moved modules, update the copy() call to the new location or move the resource back.
Example fix
// before
exportTask.copy('/META-INF/license.txt')
// after
exportTask.copy('META-INF/license.txt') Defensive patterns
Strategy: validation
Validate before calling
if (getClass().getClassLoader().getResource(resourcePath) == null) {
throw new GradleException("Can't export `" + resourcePath + "` from build-tools: not found");
} Try / catch
try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
if (is == null) throw new GradleException("resource not found: " + resourcePath);
Files.copy(is, destination, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new GradleException("Can't write resource `" + resourcePath + "` to " + destination, e);
} Prevention
- Confirm every resource path passed to copy() exists under build-tools/src/main/resources.
- Avoid leading slashes in resource paths; match case and extension exactly.
- Rebuild the build-tools jar after adding or renaming resources.
When it happens
Trigger: Calling copy('some/path') with a resource path that does not exist under build-tools' src/main/resources, or one that was not packaged into the build-tools jar.
Common situations: Resource name typo (wrong case, stray leading slash, wrong extension); resource lives in a different module; resource file deleted but copy() call not updated.
Related errors
- Unable to locate {} on build classpath.
- /version.properties resource missing
- Can't write resource `${resourcePath}` to ${destination}
- platform cannot be set on elasticsearch distribution [${name
- bundledJdk cannot be set on elasticsearch distribution [${na
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/60cc6921ea46cf79.
Report an issue: GitHub.