Backend Development 6 min read

How to Skip Unit Tests When Packaging a Maven Java Project

The article details multiple ways to skip unit tests when packaging a Maven Java project, including command‑line flags, pom.xml configuration, IDE settings, and Maven runner VM options, enabling developers to build JAR files without test execution when production configurations are needed.

Top Architect
Top Architect
Top Architect
How to Skip Unit Tests When Packaging a Maven Java Project

In this article, a senior architect explains how to package a Maven Java project without running unit tests, which is useful when production configuration is required but test databases are inaccessible.

By default, Maven's package phase depends on the test phase, so tests must pass before packaging. To bypass this, you can use command‑line parameters:

mvn package -DskipTests=true
mvn package -Dmaven.test.skip=true

The first option skips test execution but still compiles test classes; the second skips both execution and compilation.

You can also configure the pom.xml to skip tests by adding the Surefire plugin with <skip>true</skip> :

<build>
    <plugins>
        <!-- Maven skip tests during packaging -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
    </plugins>
</build>

IDE shortcuts are also covered: in IntelliJ IDEA you can enable the “Skip Tests” checkbox in the Maven Run/Debug configuration or click the “Skip Tests” icon in the toolbar before invoking the lifecycle.

Additionally, you can add the VM option -Dmaven.test.skip=true or -DskipTests=true in the Maven Runner settings (Build, Execution, Deployment → Maven → Runner) to globally skip tests during builds.

These methods allow you to generate the final JAR without being blocked by failing tests.

Javabackend developmentMavenpackagingSkipTests
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.