Effortlessly Update Maven Versions Across Hundreds of Modules

This guide shows two reliable Maven techniques—using the versions-maven-plugin and a placeholder with the flatten-maven-plugin—to safely update version numbers across dozens of modules without manual errors or risky global replacements.

Sanyou's Java Diary
Sanyou's Java Diary
Sanyou's Java Diary
Effortlessly Update Maven Versions Across Hundreds of Modules

Hello everyone, I'm sharing two practical tricks for quickly and safely updating Maven version numbers across many modules, avoiding the pitfalls of manual or blind global replace.

1

Use the versions-maven-plugin to manage versions.

Add the following plugin definition to your parent pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
</build>

Then run a single command to set a new version for all modules: mvn versions:set -DnewVersion=1.2.1 If you need to revert the change, use: mvn versions:revert Finally, commit the changes with: mvn versions:commit This approach updates the parent reference and all child module versions consistently.

2

The second method relies on a placeholder managed in the parent POM.

Define a property such as ${revision} in the parent POM:

<properties>
    <revision>2.8.5</revision>
</properties>

Use the placeholder in child modules (see image). To make Maven replace the placeholder during build, add the flatten-maven-plugin:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>flatten-maven-plugin</artifactId>
    <version>1.2.7</version>
    <configuration>
        <updatePomFile>true</updatePomFile>
        <flattenMode>resolveCiFriendliesOnly</flattenMode>
    </configuration>
    <executions>
        <execution>
            <id>flatten</id>
            <phase>process-resources</phase>
            <goals>
                <goal>flatten</goal>
            </goals>
        </execution>
        <execution>
            <id>flatten.clean</id>
            <phase>clean</phase>
            <goals>
                <goal>clean</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Now changing the revision value in the parent POM updates all modules automatically.

This pattern is used in my open‑source projects and greatly reduces the risk of version‑mismatch errors.

3

In everyday development, eliminating repetitive, error‑prone tasks boosts efficiency. If you found these tips helpful, consider starring the repository.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Build Automationmavenflatten-maven-pluginversions-maven-plugin
Sanyou's Java Diary
Written by

Sanyou's Java Diary

Passionate about technology, though not great at solving problems; eager to share, never tire of learning!

0 followers
Reader feedback

How this landed with the community

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.