elastic/elasticsearch · error · GradleException
Capturing output was not enabled. Use ${name}.getCapturedOut
Error message
Capturing output was not enabled. Use ${name}.getCapturedOutput.set(true) to enable output capturing. What it means
LoggedExec.getOutput() throws when a caller requests the captured process output but getCaptureOutput() was left at its default false. Output capturing is opt-in because it buffers the entire process output in memory (a ByteArrayOutputStream), which is wasteful when only console logging is needed. The message names the task and the exact property to flip.
Source
Thrown at build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java:241
});
} catch (Exception e) {
if (output.size() != 0) {
LOGGER.error("Exec output and error:");
NEWLINE.splitAsStream(output.toString(StandardCharsets.UTF_8)).forEach(s -> LOGGER.error("| " + s));
}
throw e;
}
}
@Override
public WorkResult delete(Object... objects) {
return fileSystemOperations.delete(d -> d.delete(objects));
}
@Internal
public String getOutput() {
if (getCaptureOutput().get() == false) {
throw new GradleException(
"Capturing output was not enabled. Use " + getName() + ".getCapturedOutput.set(true) to enable output capturing."
);
}
return output;
}
private static class IndentingOutputStream extends OutputStream {
public final byte[] indent;
private final OutputStream delegate;
IndentingOutputStream(OutputStream delegate, Object version) {
this.delegate = delegate;
indent = (" [" + version + "] ").getBytes(StandardCharsets.UTF_8);
}
@Override
public void write(int b) throws IOException {View on GitHub (pinned to db6a809a66)
Solutions
- Set getCaptureOutput().set(true) on the LoggedExec task configuration before reading getOutput().
- Note that captureOutput is incompatible with indentingConsoleOutput (see error 26) — ensure only one is set.
- If you only need the output for logging, do not call getOutput() at all; let LoggedExec log it on failure.
Example fix
// before
loggedExec {
commandLine 'some-tool'
}
// later: def out = loggedExec.getOutput() // throws
// after
loggedExec {
commandLine 'some-tool'
captureOutput = true
}
def out = loggedExec.getOutput() Defensive patterns
Strategy: validation
Validate before calling
if (!loggedExec.getCaptureOutput().get()) {
throw new IllegalStateException("Enable " + loggedExec.getName() + ".captureOutput before calling getOutput()");
} Prevention
- Always set captureOutput=true when you intend to call getOutput() later.
- Remember captureOutput is incompatible with indentingConsoleOutput.
- Refrain from calling getOutput() if you only need console logging.
When it happens
Trigger: Calling task.getOutput() on a LoggedExec task whose getCaptureOutput().get() is false (the convention default). The check runs at the point of retrieval, not at task execution, so the task may have already completed successfully before this fires.
Common situations: A downstream task or build script reads loggedExec.getOutput() to parse a command's result without first enabling capture; refactoring code that previously used Gradle's standard Exec (which captures by default) to LoggedExec (which does not).
Related errors
- Capturing output is not supported when indentingConsoleOutpu
- Cannot set commandline with empty list.
- platform cannot be set on elasticsearch distribution [${name
- bundledJdk cannot be set on elasticsearch distribution [${na
- Failed to read exec output
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/7d980a4868ed649f.
Report an issue: GitHub.