Skip to content
Latchkey

Maven -DskipTests still compiles tests (and fails) in CI

-DskipTests tells Surefire/Failsafe not to run tests, but testCompile still runs, so a broken test source still fails the build. To skip compiling tests entirely you need -Dmaven.test.skip=true.

What this error means

A build invoked with -DskipTests still fails at maven-compiler-plugin:testCompile with a "cannot find symbol" or other compile error in a test class.

mvn output
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.13.0:testCompile (default-testCompile)
on project app: Compilation failure:
[ERROR] /src/test/java/com/example/AppTest.java:[12,30] cannot find symbol

Common causes

skipTests does not skip test compilation

-DskipTests only skips test execution. The test-compile phase still runs, so a test source that does not compile fails the build.

A stale or broken test source

A test references a symbol that no longer exists, and because tests still compile, the error surfaces despite skipping execution.

How to fix it

Fix the test source (preferred)

Repair the test that does not compile rather than masking it; tests should stay buildable.

Skip test compilation when you truly mean it

Use -Dmaven.test.skip=true to skip both compiling and running tests.

Terminal
mvn -B -Dmaven.test.skip=true package

How to prevent it

  • Keep test sources compiling even when execution is skipped.
  • Know the difference: skipTests skips running, maven.test.skip skips compiling too.
  • Avoid shipping packages built with all tests skipped.

Frequently asked questions

What causes "-DskipTests vs -Dmaven.test.skip"?
-DskipTests only skips test execution. The test-compile phase still runs, so a test source that does not compile fails the build.
How do I fix -DskipTests vs -Dmaven.test.skip?
Repair the test that does not compile rather than masking it; tests should stay buildable.

Related guides

References

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