Maven "Failed to execute goal ... compile" - Fix Compilation in CI
The maven-compiler-plugin failed during compile. The headline is generic; the real cause is the COMPILATION ERROR block beneath it - a cannot find symbol, a type error, or missing source. Fix the code, not the plugin.
What this error means
The build stops in the compile phase with Failed to execute goal ...:compile ... Compilation failure, followed by javac diagnostics naming files, lines, and symbols.
[ERROR] COMPILATION ERROR :
[ERROR] /src/main/java/com/example/App.java:[42,17] cannot find symbol
symbol: method calculate(int)
location: class com.example.Calculator
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile)
on project app: Compilation failureCommon causes
A real source error (cannot find symbol, type mismatch)
A missing import, a renamed method, or a type error makes javac fail. The plugin just reports the compiler’s own diagnostics.
Generated sources or a dependency missing in CI
If annotation-processed or generated sources are not produced, or a needed dependency is absent in CI, references resolve locally but not in the pipeline.
How to fix it
Read the COMPILATION ERROR block and fix the source
The lines above the goal wrapper name the exact file, line, and symbol. Reproduce locally and fix it.
mvn -B clean compile
# the file:[line,col] and "cannot find symbol" lines pinpoint the errorEnsure generated sources and deps exist in CI
- Run the phase that generates sources (annotation processors, codegen) before compile.
- Confirm every dependency referenced by the failing code is on the classpath in CI.
- Build a clean checkout locally to reproduce - stale local artifacts can hide a missing dep.
How to prevent it
- Build a clean checkout in CI (
clean compile) so stale local state never masks errors. - Pin annotation processors and codegen plugins so generated sources are reproducible.
- Run the compile on every PR to catch source errors before merge.