Skipping Unchanged Maven Modules | Generated by AI

Home 2026.05

Question: How can I skip or opt out of a Maven module during a build to speed up the build process, especially if the module hasn’t changed? Suppose I have a project like PAUWeb with Angular frontend, Java 8 backend, and 10 modules, and one module contributes 2 minutes to a 6-minute build.

Answer:

Yes, skipping modules that haven’t changed can speed up your Maven build significantly. There are several strategies you can use in Maven to “opt out” or skip certain modules:


1. Use the -pl (projects) and -am (also make) flags

Maven allows you to build only specific modules with -pl (projects list). For example:

# Build only moduleA and moduleB
mvn clean install -pl moduleA,moduleB

Example skipping a module:

If moduleX takes 2 minutes and hasn’t changed:

mvn clean install -pl !moduleX

2. Use maven.test.skip or skipTests

If your build is slow because of tests in a module, you can skip tests:

mvn install -DskipTests

3. Use -am with selective builds

If modules are interdependent, building only changed modules with -pl + -am ensures dependencies are also built:

mvn install -pl moduleA -am

This builds moduleA and any modules it depends on, skipping unrelated modules.


4. Incremental Builds / mvn reactor

Maven doesn’t automatically skip unchanged modules by default. To handle that:

Example with incremental plugin:

<plugin>
  <groupId>io.takari.maven.plugins</groupId>
  <artifactId>takari-lifecycle-plugin</artifactId>
  <version>1.13.6</version>
</plugin>

This allows building only changed modules.


5. Angular frontend optimization

If Angular build is part of the module:


6. Profile-based skipping

You can define Maven profiles to skip certain modules:

<profiles>
  <profile>
    <id>skip-moduleX</id>
    <modules>
      <module>module1</module>
      <module>module2</module>
      <!-- do not include moduleX -->
    </modules>
  </profile>
</profiles>

Then:

mvn clean install -Pskip-moduleX

Recommendation for your case:

mvn install -pl !moduleX

This can reduce your build from 6 minutes to ~4 minutes if moduleX hasn’t changed.


References:


If you want, I can show a ready-to-use Maven command for PAUWeb that skips unchanged modules automatically based on Git diffs. That can save you several minutes per build. Do you want me to do that?


Back Donate