Skip to content
Latchkey

Maven Compile "package ... does not exist" - Fix Classpath in CI

javac could not find a package referenced by your code because the library providing it is not on the compile classpath. The dependency is missing, declared at the wrong scope, or a sibling module was not built.

What this error means

The compile goal fails with package com.example.x does not exist and cannot find symbol for classes in that package. Compilation stops before tests run.

mvn output
[ERROR] /workspace/src/main/java/com/example/App.java:[5,23]
package com.acme.util does not exist
[ERROR] cannot find symbol: class Helper

Common causes

Dependency missing or at the wrong scope

The library is not declared, or it is test/provided/runtime scope when the main code needs it at compile scope, so the package is invisible to javac.

Sibling module not built

In a multi-module build, the module providing the package was not built/installed first, so its classes are absent from the compile classpath.

How to fix it

Declare the dependency at compile scope

Add the library so the package is on the main compile classpath (default scope is compile).

pom.xml
<dependency>
  <groupId>com.acme</groupId>
  <artifactId>util</artifactId>
  <version>1.4.0</version>
</dependency>

Build required modules together

For multi-module builds, build the target module with its upstream modules.

Terminal
mvn -B -pl :app -am clean install

How to prevent it

  • Declare compile-time libraries at compile scope, build multi-module projects with -am, and verify scopes with mvn dependency:tree.

Frequently asked questions

What causes ""package ... does not exist""?
The library is not declared, or it is test/provided/runtime scope when the main code needs it at compile scope, so the package is invisible to javac.
How do I fix "package ... does not exist"?
Add the library so the package is on the main compile classpath (default scope is compile).

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card