Backend Development 6 min read

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 :

<code>&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
            &lt;artifactId&gt;versions-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.3&lt;/version&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;</code>

Then run a single command to set a new version for all modules:

<code>mvn versions:set -DnewVersion=1.2.1</code>

If you need to revert the change, use:

<code>mvn versions:revert</code>

Finally, commit the changes with:

<code>mvn versions:commit</code>

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:

<code>&lt;properties&gt;
    &lt;revision&gt;2.8.5&lt;/revision&gt;
&lt;/properties&gt;</code>

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

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

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.

javabuild 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

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.