Skip to content
Latchkey

Gradle "Execution failed for task" - Diagnose and Fix in CI

Execution failed for task is Gradle’s generic failure wrapper. The actual error is always in the What went wrong block beneath it - a compile error, a failing test, or a process that exited non-zero.

What this error means

The build stops with Execution failed for task ':module:taskName' followed by a Caused by/What went wrong section. The task name tells you the phase; the detail below tells you the cause.

gradle output
> Task :app:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:test'.
> There were failing tests. See the report at: file://.../build/reports/tests/test/index.html

Common causes

A downstream task failed

The wrapper names the task; the cause is task-specific - :compileJava means a compile error, :test means failing tests, an Exec task means a non-zero exit from a spawned process.

A plugin or script threw during execution

Custom build logic or a plugin can throw at execution time. The Caused by stack trace points at the offending code.

How to fix it

Read the What-went-wrong block and get a stacktrace

Re-run with --stacktrace (or --info) so the real exception and its origin are visible.

Terminal
./gradlew :app:test --stacktrace --info

Open the task-specific report

  1. For :test, open build/reports/tests/test/index.html for the failing assertions.
  2. For :compileJava, fix the compile error shown above the wrapper.
  3. For an Exec task, check the exit code and the command’s own stderr.

How to prevent it

  • Always run CI Gradle with --stacktrace so failures are diagnosable from logs.
  • Upload Gradle reports as CI artifacts for post-mortem.
  • Keep custom build logic in tested, well-scoped plugins rather than inline scripts.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →