Backend Development 6 min read

Using a Maven Plugin to Incrementally Compile and Skip Tests for Faster Builds

The article explains how a Maven plugin can automatically compile only changed files and skip unit tests when code is unchanged, dramatically reducing build time, and provides step‑by‑step instructions with the necessary pom.xml configuration and a sample XML snippet.

FunTester
FunTester
FunTester
Using a Maven Plugin to Incrementally Compile and Skip Tests for Faster Builds

If you start a new Java project, Gradle is usually the first choice, but Maven still has advantages in certain scenarios, and you often need plugins to provide additional build functionality.

The Maven Java compiler plugin supports incremental compilation, yet it cannot handle extreme cases such as triggering compilation when source files change or skipping unit tests when no code changes are made.

Trigger compilation when source files are modified.

Skip unit tests when the code has not changed.

In most cases, to handle deleted files you must run mvn clean install , which compiles the entire codebase and runs all unit tests.

Fortunately, a plugin exists that solves both problems:

After code changes, it compiles the affected files and triggers a full build.

When there is no code change, it skips the execution of unit tests.

These two features can greatly reduce compilation time because usually only a few modules change and previous build outputs can be reused. Enabling this plugin allows for rapid builds.

How to Use the Plugin

The plugin is added in the pre‑clean phase by inserting the following entry into pom.xml and running mvn pre-clean install :

<plugin>
    <groupId>mavenplugin</groupId>
    <artifactId>compilerplugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <executions>
        <execution>
            <id>pre-clean</id>
            <phase>pre-clean</phase>
            <goals>
                <goal>inc</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Disclaimer: This article was first published by the public account “FunTester”. Please follow and engage, and do not repost without permission.

Selected Technical Articles

Linux Performance Monitoring Tool netdata – Chinese Translation

Performance Testing Framework – Third Edition

Illustrated HTTP Mind Map

Graphical Output of Performance Test Data

Measuring Asynchronous Write Interface Latency in Load Tests

Quantitative Performance Testing for Multiple Login Methods

JMeter Throughput Error Analysis

Multi‑Project Login Conflict Test Cases

Selected Non‑Code Articles

Programming Mindset for Everyone

JSON Basics

2020 Tester Self‑Improvement Guide

Pitfalls for Automation Beginners (Part 1)

Pitfalls for Automation Beginners (Part 2)

How to Become a Full‑Stack Automation Engineer

Manual Testing vs. Automated Testing?

Why Automation Testing Projects Fail

Simplifying Test Cases

Javabuild optimizationGradleMavenIncremental CompilationUnit Test Skipping
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

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.