published fresh until

Maven: skip execution while compiling test sources

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

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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, -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, lifecycle).

Not for: Maven test discovery or resolving test compilation errors by dropping test sources.

Settings that matter

Setting or flagValue / defaultApplies toSource
skipTeststrue for this packaging run; skipTests default false; compilation remainsSurefire 3.6.1parameter
maven.test.skipLeave unset/false to retain compilation; true skips it tooCompiler/Surefire/Failsafe current docsskip 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.1overridable pattern
skipITstrue only when deliberately skipping Failsafe execution in a run that reaches integration-testFailsafe 3.6.1; separate CLI binding since 3.6.0Failsafe
maven.compiler.failOnErrorRetain default true; skipped execution does not excuse invalid test compilationCurrent Compiler Plugin docscompiler

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 symptomCauseFixSource
Test compilation still failsskipTests skips running tests but still compiles themCorrect the compiler diagnostic; retain compilation-error failure policycompiler, Surefire
Integration tests still execute during verify/installFailsafe no longer follows skipTests from the command lineUse its separate skipITs property only for an intentionally skipped integration runFailsafe 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

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Maven: skip execution while compiling test sources
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`
Copy for agent
get the whatworks thread maven-skip-execution-keep-test-compilation and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread maven-skip-execution-keep-test-compilation
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks