# Gradle ":compileJava" Fails: "cannot find symbol" - Fix in CI

> Fix Gradle ":compileJava FAILED" with "error: cannot find symbol" in CI - a missing dependency on the compile classpath, a generated source not produced, or a package/class that no longer exists.

Source: https://latchkey.dev/learn/java-jvm/gradle-compilejava-symbol-not-found  
Updated: 2026-06-26

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.

## Diagnose 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.

```Terminal
# 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 -version
```

> A JVM or Gradle version mismatch between your machine and the runner explains a large share of CI-only Gradle failures. Pin the JDK with `setup-java` and pin Gradle with the wrapper, then confirm both with `./gradlew -version` in CI.

## 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=warn` first 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.

## FAQ

### What causes Gradle ":compileJava" Fails: "cannot find symbol"?

There are 2 common causes: dependency missing from the compile classpath and generated source not produced. 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.

### How do I fix Gradle ":compileJava" Fails: "cannot find symbol"?

There are 2 fixes depending on which cause you have: add the dependency to the right configuration and verify generation and classpath. Work through them in order, since the first is the most common.

### What does Gradle ":compileJava" Fails: "cannot find symbol" actually mean?

The :compileJava task fails with error: cannot find symbol, pointing at a class, method, or variable.

### How do I stop Gradle ":compileJava" Fails: "cannot find symbol" happening again?

Declare compile-time dependencies as implementation/api, wire annotation processors via annotationProcessor, and keep generated-source tasks in the compile graph.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
