maven share dependencies among different modules

后端 未结 2 1764
刺人心
刺人心 2020-12-21 14:02

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 dep

相关标签:
2条回答
  • 2020-12-21 14:38

    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>
    
    0 讨论(0)
  • 2020-12-21 14:55

    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.

    0 讨论(0)
提交回复
热议问题