What this thread does
Do first: run mvn package -DskipTests=true to skip Surefire execution while retaining test compilation.
Short answer
As of November 2026, Maven 3.10.2 and Surefire 3.6.1 distinguish skipping execution from skipping compilation. Keep maven.test.skip unset or false when compiled test classes are required. The compiler failOnError default is true (compiler contract).
Choose / don't choose
- Packaging with compiled tests: choose
-DskipTests=true; don't use-Dmaven.test.skip=true, which also bypasses test compilation (Surefire). - Ordinary CI gate: keep the property false unless the packaging run explicitly opts out; don't bake a literal true into Surefire configuration when CI needs an overridable choice (property indirection).
- Integration tests on later phases: inspect Failsafe separately. Since Failsafe 3.6.0,
-DskipTestsskips Surefire only; setskipITstotruewhen integration-test execution should also be skipped. The lifecycle listspackagebeforepre-integration-test(Failsafe, lifecycle).
Not for: Maven test discovery or resolving test compilation errors by dropping test sources.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
skipTests | true for this packaging run; skipTests default false; compilation remains | Surefire 3.6.1 | parameter |
maven.test.skip | Leave unset/false to retain compilation; true skips it too | Compiler/Surefire/Failsafe current docs | skip behavior, compiler |
<skipTests>${skipTests}</skipTests> | Bind plugin configuration to a POM property; the linked example sets the property to true and overrides with -DskipTests=false; this card's false default with a -DskipTests=true override is the same pattern inverted (adaptation, not shown on the page) | Surefire 3.6.1 | overridable pattern |
skipITs | true only when deliberately skipping Failsafe execution in a run that reaches integration-test | Failsafe 3.6.1; separate CLI binding since 3.6.0 | Failsafe |
maven.compiler.failOnError | Retain default true; skipped execution does not excuse invalid test compilation | Current Compiler Plugin docs | compiler |
Order of operations
1. Expose a property so the package run can opt out without disabling normal test execution. Inside the existing POM, adapt the documented property pattern (the example uses the opposite default; this inverts it):
<properties><skipTests>false</skipTests></properties>
<!-- inside the maven-surefire-plugin configuration -->
<skipTests>${skipTests}</skipTests>
These are fragments for two separate POM locations (Surefire example). 2. Run mvn package -DskipTests=true. The lifecycle includes generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, and test. Their bound goals run; skipTests=true skips running tests (phase reference). 3. If test-compile fails, repair the test source, test-scoped dependency or compiler configuration named by its diagnostic. Do not replace the execution-only flag with a compilation skip when the deliverable needs compiled tests (compiler). 4. Confirm compiled classes and expected package outputs in the build's configured output locations. A phase with bound goals executes those goals; skipTests is not a universal lifecycle cancellation switch (goal bindings).
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
| Test compilation still fails | skipTests skips running tests but still compiles them | Correct the compiler diagnostic; retain compilation-error failure policy | compiler, Surefire |
| Integration tests still execute during verify/install | Failsafe no longer follows skipTests from the command line | Use its separate skipITs property only for an intentionally skipped integration run | Failsafe boundary |
vks' packaging report describes unwanted test execution during packaging; current plugin docs supply the execution/compilation distinction.
Missing
- Custom test runners and extra plugin executions may use different skip parameters. The POM's actual bindings must be inspected before promising that all side effects are suppressed.
Checked
2026-11-12; Maven release history, Surefire/Failsafe 3.6.1 skip references, compiler and lifecycle references plus the dated packaging report read. No Maven commands executed.
Started from a post by @Apache Maven, packaged by the editor. Original post