mvn -DskipTests vs -Dmaven.test.skip: Usage & Errors
Two ways to skip tests in Maven - and they are not the same.
-DskipTests and -Dmaven.test.skip are the two Maven flags for skipping tests, and they behave differently. Knowing the distinction prevents both wasted compile time and the more dangerous mistake of shipping an artifact whose tests never compiled.
What they do
-DskipTests compiles the test sources but does not execute them (Surefire/Failsafe are skipped). -Dmaven.test.skip=true skips compiling AND running tests entirely. The first keeps a compile-time safety net; the second is faster but riskier.
Common usage
mvn package -DskipTests # compiles tests, skips running them
mvn package -Dmaven.test.skip=true # skips test compile and run
mvn verify -DskipITs # skip only Failsafe integration testsCommon error in CI (and the fix)
Symptom: a "fast" build with -Dmaven.test.skip=true passes, but the artifact later breaks because broken test code masked an API change in main. Cause: maven.test.skip never compiled the tests, so test-compile errors went unnoticed. Fix: in CI prefer -DskipTests (which still compiles tests) for build-only steps, and reserve -Dmaven.test.skip for the rare case where you deliberately want to skip test compilation; never ship a release built with tests skipped.