Manage version of sub-projects in a Maven parent project

When you develop an application with different Maven projects, we will often use a Maven parent project to manage these Maven projects. It will help us to centralize the version management of the dependencies used for the application, when we want to upgrade the version of a dependency, we just need to change it in the pom.xml file of the Maven parent project. One need is how we can manage the version of these Maven sub-projects so that when we need to upgrade the application’s version, we will only need to change one place.

For example, I have a Maven parent project with the content of pom.xml file as follows:

with maven-example1 sub-project has pom.xml file with the following content:

and maven-example2 sub-project has pom.xml file with the following content:

Now my need is that when I want to upgrade the version of the application, I just need to change it in the pom.xml file of the Maven parent project, which can be effective on sub-projects, no need to change for each pom.xml of sub-project! 🙂

What is your solution? I suggest the following solution:

Add a property in the pom.xml file of the Maven parent project, for example:

Then use this property to declare the parent project:

and all parent project declarations in sub-projects are as follows:

and:

Running build parent project, you will see the following results:

Change the value of property ${global.version} to 1.0 and rebuild, you will see the following results:

Very convenient, right?

Add Comment