Gradle "Task :compileJava FAILED" - Fix Compilation in CI
Task :compileJava FAILED means javac rejected your source. Gradle prints the compiler diagnostics just above the failure line - a missing symbol, a type error, or a missing dependency on the compile classpath.
What this error means
The build stops with > Task :compileJava FAILED and a Compilation failed; see the compiler error output for details, preceded by javac errors naming files, lines, and symbols.
> Task :app:compileJava FAILED
/app/src/main/java/com/example/App.java:42: error: cannot find symbol
calc.calculate(10);
^
symbol: method calculate(int)
2 errorsCommon causes
A real source error
A missing import, renamed method, or type mismatch makes javac fail. Gradle surfaces the compiler’s own diagnostics above the FAILED line.
Missing dependency or generated source in CI
A dependency absent from the compile classpath, or annotation-processed/generated code that was not produced, makes references unresolvable in the pipeline.
How to fix it
Read the javac errors and reproduce locally
The file:line/error lines pinpoint the failure. Re-run the single task with more output.
./gradlew :app:compileJava --console=plain --infoCheck the compile classpath and codegen
- Confirm the dependency providing the missing symbol is on
implementation/compileOnly. - Run the task that generates sources before compileJava if codegen is involved.
- Build a clean checkout so stale outputs do not mask a missing dependency.
How to prevent it
- Build clean in CI so stale outputs never hide compile errors.
- Declare dependencies in the correct configuration (implementation vs compileOnly).
- Run compileJava on every PR to catch source errors before merge.