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

  1. Set getCaptureOutput().set(true) on the LoggedExec task configuration before reading getOutput().
  2. Note that captureOutput is incompatible with indentingConsoleOutput (see error 26) — ensure only one is set.
  3. 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

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


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