3

I have a project with 5 modules.

2 of the modules have a dependency of hibernate. they are siblings and not parent child hence one cannot inherit another one's dependencies

is there a way to specify hibernate related dependency in parent and make the 2 modules inherit it and the other 3 modules wont inherit it.

user373201
  • 10,945
  • 34
  • 112
  • 168

2 Answers2

4

Yes there is. Create a parent pom.xml with the shared hibernate dependency and add a parent declaration to your 2 modules:

<parent>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    <relativePath>...path-to-parent.../pom.xml</relativePath>
</parent>

Declare the hibernate dependency in the dependencies section of your parent pom:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
Carles Barrobés
  • 11,608
  • 5
  • 46
  • 60
  • right now all my 5 modules do that. my parent has junit dependcy and it is shared by all 5 modules. If I do as you say all 5 modules will inherit hibernate, but I want only 2 modules to inherit it. – user373201 Dec 31 '10 at 15:05
  • sorry I didn't gather that from your post. Maybe you can create a multiple hierarchy: root -> (a, b, c, d), and d -> (e, f) where d is a new project with the hibernate dependency, a,b,c the projects that don't need it, and e,f the ones that do – Carles Barrobés Dec 31 '10 at 16:21
  • see [here](http://stackoverflow.com/questions/1636801/can-maven-projects-have-multiple-parents/1637541#1637541) for ahother SO answer on deeper maven hierarchies – Carles Barrobés Dec 31 '10 at 16:44
0

Consider using a separate project to model the set of dependencies, and then depend on that project. This is more flexible than trying to model it in your parent hierarchy somehow.

Ed Staub
  • 15,480
  • 3
  • 61
  • 91