elastic/elasticsearch · error · GradleException

Capturing output is not supported when indentingConsoleOutpu

Error message

Capturing output is not supported when indentingConsoleOutput is configured.

What it means

LoggedExec.run() throws at task execution when both getCaptureOutput() is true AND getIndentingConsoleOutput() is present. The two modes are mutually exclusive: capture buffers output to a ByteArrayOutputStream for later getOutput() retrieval, while indenting streams output directly to System.out with a version-prefixed indent. Enabling both is contradictory (you cannot both buffer for later and stream live).

Source

Thrown at build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java:145

        getNonTrackedEnvironment().putAll(providerFactory.environmentVariablesPrefixedBy("VAULT"));
        Provider<String> javaToolchainHome = providerFactory.environmentVariable("JAVA_TOOLCHAIN_HOME");
        if (javaToolchainHome.isPresent()) {
            getEnvironment().put("JAVA_TOOLCHAIN_HOME", javaToolchainHome);
        }
        Provider<String> javaRuntimeHome = providerFactory.environmentVariable("RUNTIME_JAVA_HOME");
        if (javaRuntimeHome.isPresent()) {
            getEnvironment().put("RUNTIME_JAVA_HOME", javaRuntimeHome);
        }
        Provider<String> path = providerFactory.environmentVariable("PATH");
        if (path.isPresent()) {
            getEnvironment().put("PATH", path);
        }
    }

    @TaskAction
    public void run() {
        if (getCaptureOutput().get() && getIndentingConsoleOutput().isPresent()) {
            throw new GradleException("Capturing output is not supported when indentingConsoleOutput is configured.");
        }
        Consumer<Logger> outputLogger;
        OutputStream out = new ByteArrayOutputStream();
        outputLogger = getIndentingConsoleOutput().isPresent() ? logger -> {} : logger -> logger.error(byteStreamToString(out));

        OutputStream finalOutputStream = getIndentingConsoleOutput().isPresent()
            ? new IndentingOutputStream(System.out, getIndentingConsoleOutput().get())
            : out;
        ExecResult execResult = execOperations.exec(execSpec -> {
            execSpec.setIgnoreExitValue(true);
            execSpec.setStandardOutput(finalOutputStream);
            execSpec.setErrorOutput(finalOutputStream);
            execSpec.setExecutable(getExecutable().get());
            execSpec.environment(getEnvironment().get());
            execSpec.environment(getNonTrackedEnvironment().get());
            if (getArgs().isPresent()) {
                execSpec.setArgs(getArgs().get());
            }

View on GitHub (pinned to db6a809a66)

Solutions

  1. If you need programmatic access to output, keep captureOutput=true and remove indentingConsoleOutput.
  2. If you want indented live console output, keep indentingConsoleOutput and remove captureOutput (you cannot call getOutput()).
  3. Split into two LoggedExec tasks if both behaviors are genuinely needed for different consumers.

Example fix

// before
loggedExec {
  captureOutput = true
  indentingConsoleOutput = '8.0' // throws at execution
}
// after (choose one)
loggedExec {
  captureOutput = true
}
// OR
loggedExec {
  indentingConsoleOutput = '8.0'
}
Defensive patterns

Strategy: validation

Validate before calling

if (loggedExec.getCaptureOutput().get() && loggedExec.getIndentingConsoleOutput().isPresent()) {
    throw new IllegalStateException("captureOutput and indentingConsoleOutput are mutually exclusive on " + loggedExec.getName());
}

Prevention

When it happens

Trigger: Configuring a LoggedExec task with both getCaptureOutput().set(true) and getIndentingConsoleOutput().set(someVersion) on the same task instance. The check runs at @TaskAction time, so the failure appears during task execution, not configuration.

Common situations: Copy-pasting task config that set captureOutput for programmatic output access while another block set indentingConsoleOutput for pretty CI logs; upgrading Gradle task definitions where these were previously compatible.

Related errors


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