Gradle ":compileJava" Fails: "cannot find symbol" - Fix in CI
javac could not resolve a referenced symbol while Gradle compiled your code. The class is not on the compile classpath, a generated source was not produced, or the reference is stale.
What this error means
The :compileJava task fails with error: cannot find symbol, pointing at a class, method, or variable. The build stops at compilation; nothing downstream runs.
> Task :app:compileJava FAILED
src/main/java/com/example/App.java:12: error: cannot find symbol
import com.acme.util.Helper;
^
symbol: class Helper
location: package com.acme.utilDiagnose it: get the real failure out of Gradle
Gradle summarises failures aggressively, and the top-level message frequently describes a downstream symptom rather than the cause. Re-run the failing task with diagnostics before changing build logic.
# the actual stack, plus what Gradle decided about the build
./gradlew <task> --stacktrace --info
# is a stale daemon or cache involved?
./gradlew --stop
./gradlew <task> --no-daemon --no-build-cache
# what does Gradle think the environment is?
./gradlew -versionCommon causes
Dependency missing from the compile classpath
A library is declared runtimeOnly/testImplementation (or not at all) when the code needs it at compile time, so the symbol is not visible to javac.
Generated source not produced
Code generated by an annotation processor or a codegen task (e.g. MapStruct, generated DTOs) was not produced, so the referenced class does not exist yet.
How to fix it
Add the dependency to the right configuration
Declare the library as implementation (or api) so it is on the compile classpath.
dependencies {
implementation("com.acme:util:1.4.0")
annotationProcessor("org.mapstruct:mapstruct-processor:1.6.0")
}Verify generation and classpath
- Run
./gradlew :app:dependencies --configuration compileClasspathto confirm the library is present. - Ensure annotation processors are declared via
annotationProcessor(...), not justimplementation(...). - Clean stale outputs with
./gradlew cleanif generated sources went out of sync.
Configuration cache and CI
- The configuration cache rejects build logic that reads mutable state at execution time, which is why enabling it surfaces errors an existing build never showed.
- Run with
--configuration-cache-problems=warnfirst to see the full list rather than failing on the first one. - A cached configuration keyed to a different environment is worse than none. Include the JDK version in your cache key.
How to prevent it
- Declare compile-time dependencies as
implementation/api, wire annotation processors viaannotationProcessor, and keep generated-source tasks in the compile graph.