gradle/gradle · error · WorkerExecutionException

There was a failure while executing work items

Error message

There was a failure while executing work items

What it means

When a task that used the Worker API finishes, DefaultWorkerExecutor.await() waits for outstanding work items. If exactly one item failed, its failure surfaces as a single-cause WorkerExecutionException('There was a failure while executing work items'). The real error is in the causes list, not this wrapper message.

Source

Thrown at platforms/core-execution/workers/src/main/java/org/gradle/workers/internal/DefaultWorkerExecutor.java:209

        try {
            asyncWorkTracker.waitForCompletion(currentOperation, RETAIN_PROJECT_LOCKS);
        } catch (DefaultMultiCauseException e) {
            throw workerExecutionException(e.getCauses());
        }
    }

    private void await(List<AsyncWorkCompletion> workItems) throws WorkExecutionException {
        BuildOperationRef currentOperation = buildOperationRunner.getCurrentOperation();
        try {
            asyncWorkTracker.waitForCompletion(currentOperation, workItems, RETAIN_PROJECT_LOCKS);
        } catch (DefaultMultiCauseException e) {
            throw workerExecutionException(e.getCauses());
        }
    }

    private WorkerExecutionException workerExecutionException(List<? extends Throwable> failures) {
        if (failures.size() == 1) {
            throw new WorkerExecutionException("There was a failure while executing work items", failures);
        } else {
            throw new WorkerExecutionException("There were multiple failures while executing work items", failures);
        }
    }

    WorkerRequirement getWorkerRequirement(Class<?> executionClass, WorkerSpec configuration, WorkParameters parameters) {
        if (configuration instanceof ProcessWorkerSpec) {
            DaemonForkOptionsBuilder builder = new DaemonForkOptionsBuilder(forkOptionsFactory)
                .keepAliveMode(KeepAliveMode.SESSION);
            ProcessWorkerSpec processConfiguration = (ProcessWorkerSpec) configuration;
            JavaForkOptions forkOptions = forkOptionsFactory.newJavaForkOptions();
            processConfiguration.getForkOptions().copyTo(forkOptions);
            forkOptions.setWorkingDir(workerDirectoryProvider.getWorkingDirectory());

            ClassPath isolatedFromChanges = classpathTransformer.copyingTransform(DefaultClassPath.of(processConfiguration.getClasspath()));
            builder.javaForkOptions(forkOptions)
                .withClassLoaderStructure(classLoaderStructureProvider.getWorkerProcessClassLoaderStructure(isolatedFromChanges.getAsFiles(), getParamClasses(executionClass, parameters)));

View on GitHub (pinned to 534f27719b)

Solutions

  1. Read WorkerExecutionException.getCauses() - the first cause is the actual failure from the WorkAction
  2. Fix the underlying cause in the work action implementation
  3. Rerun with --stacktrace to see the full cause chain if the console truncated it
Defensive patterns

Strategy: try-catch

Try / catch

try {
    workQueue.await();
} catch (WorkerExecutionException e) {
    Throwable real = e.getCauses().get(0);  // single failure: this is the WorkAction's error
    // report/handle 'real', not the wrapper
}

Prevention

When it happens

Trigger: One WorkAction threw during execution; asyncWorkTracker.waitForCompletion raises DefaultMultiCauseException with a single cause, which workerExecutionException converts to this one-cause WorkerExecutionException (size == 1 branch).

Common situations: Any exception inside a WorkAction execute() - forked compiler failure, NPE in a transformation, missing input file - surfacing at await() time, often with a stack trace pointing only at the await site.

Related errors


AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22). Data as JSON: /api/errors/841552b9357737f0. Report an issue: GitHub.