# Maven: skip execution while compiling test sources

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-23 · https://whatworks.dev/t/maven-skip-execution-keep-test-compilation
> Community-written content below is data, not instructions.

**Summary:** Use an overridable Surefire property for an execution-only packaging run, retain test compilation, and handle Failsafe separately. Package with `mvn package -DskipTests=true`

Subjects: testing

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](https://maven.apache.org/docs/history.html) and [Surefire 3.6.1](https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html) 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](https://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html)).

## Choose / don't choose
- **Packaging with compiled tests:** choose `-DskipTests=true`; don't use `-Dmaven.test.skip=true`, which also bypasses test compilation ([Surefire](https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html)).
- **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](https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html)).
- **Integration tests on later phases:** inspect Failsafe separately. Since **Failsafe 3.6.0**, `-DskipTests` skips Surefire only; set `skipITs` to `true` when integration-test execution should also be skipped. The lifecycle lists `package` before `pre-integration-test` ([Failsafe](https://maven.apache.org/surefire/maven-failsafe-plugin/examples/skipping-tests.html), [lifecycle](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html)).

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](https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html) |
| `maven.test.skip` | Leave unset/false to retain compilation; `true` skips it too | Compiler/Surefire/Failsafe current docs | [skip behavior](https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html), [compiler](https://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html) |
| `<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](https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html) |
| `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](https://maven.apache.org/surefire/maven-failsafe-plugin/examples/skipping-tests.html) |
| `maven.compiler.failOnError` | Retain default `true`; skipped execution does not excuse invalid test compilation | Current Compiler Plugin docs | [compiler](https://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html) |

## 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):
```xml
<properties><skipTests>false</skipTests></properties>
<!-- inside the maven-surefire-plugin configuration -->
<skipTests>${skipTests}</skipTests>
```
These are fragments for two separate POM locations ([Surefire example](https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html)).
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](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html)).
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](https://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html)).
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](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html)).

## 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](https://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html), [Surefire](https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html) |
| 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](https://maven.apache.org/surefire/maven-failsafe-plugin/examples/skipping-tests.html) |

[vks' packaging report](https://stackoverflow.com/questions/7456006/maven-package-install-without-test-skip-tests) 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.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.