简体   繁体   中英

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

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?

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.

Have you got any war dependencies?

There is an open jira which might be related to the problem you are facing:

(MNG-2241) Versions are required when it shouldn't with multi-modules projects and war dependencies

What I do for this is define dependency versions that I need to repeat as a property in the parent project. So:

<properties>
  ...
  <guice.version>2.0</guice.version>
</properties>

And then:

<dependency>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <version>${guice.version}</version>
</dependency>

Not exactly what you're asking for maybe, but it means you only have to change the version in one place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM