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.
[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 symbolCommon 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.
mvn -B -Dmaven.test.skip=true packageHow to prevent it
- Keep test sources compiling even when execution is skipped.
- Know the difference:
skipTestsskips running,maven.test.skipskips compiling too. - Avoid shipping packages built with all tests skipped.