tags:

views:

32

answers:

3

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?

A: 

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

dogbane
A: 

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.

ColinD
+2  A: 

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.

matt b
Not sure what the OP did exactly but this is the right answer :)
Pascal Thivent