开发者

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

开发者 https://www.devze.com 2023-01-19 21:51 出处:网络
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 i开发者_JAVA技巧n the parent project.This is so I don\'t nee

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 i开发者_JAVA技巧n 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号