Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get my sub projects to inherit dependency versions from the super project in a multi module Maven project?

Tags:

java

maven-2

I have a multi module Maven project and I want the sub projects to inherit the versions for third party dependencies which I have specified in the parent project. This is so I don't need to replicate version numbers everywhere. It's not working though and when I leave out the version number on the children I get the error:

dependencies.dependency.version is missing

What do I need to change to get this working?

like image 994
HenryTyler2 Avatar asked Oct 10 '10 12:10

HenryTyler2


People also ask

How do I add a project as a dependency of another project in Maven?

Right-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.

Is there a difference between inheriting from a parent project and being managed by a multi module project?

There is a difference between inheriting from a parent project and being managed by a multimodule project. A parent project is one that passes its values to its children. A multimodule project simply manages a group of other subprojects or modules.

What is the Packaging type of an aggregator POM in a multi module Maven project?

2. Maven's Multi-Module Project. A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom.

Does Maven support automatic parenting?

Backward Compatibility − You can easily port the multiple modules of a project into Maven 3 from older versions of Maven. It can support the older versions also. Automatic parent versioning − No need to specify the parent in the sub module for maintenance.


1 Answers

The <dependencyManagement> section of the parent POM is meant for this purpose:

dependencyManagement: is used by POMs to help manage dependency information across all of its children. If the my-parent project uses dependencyManagement to define a dependency on junit:junit:4.0, then POMs inheriting from this one can set their dependency giving the groupId=junit and artifactId=junit only, then Maven will fill in the version set by the parent. The benefits of this method are obvious. Dependency details can be set in one central location, which will propagate to all inheriting POMs. In addition, the version and scope of artifacts which are incorporated from transitive dependencies may also be controlled by specifying them in a dependency management section.

like image 97
matt b Avatar answered Sep 27 '22 16:09

matt b