Maven在不同模块之间共享依赖项 [英] maven share dependencies among different modules

查看:114
本文介绍了Maven在不同模块之间共享依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5个模块的项目.

I have a project with 5 modules.

2个模块具有休眠状态的依赖关系.他们是兄弟姐妹,不是父母的孩子,因此一个人不能继承另一个人的依赖关系

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

有没有一种方法可以在父对象中指定与休眠相关的依赖关系,并使2个模块继承它,而其他3个模块则不会继承它.

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.

推荐答案

是的.创建具有共享休眠依赖项的父pom.xml并将父声明添加到您的2个模块中:

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>

在父pom的依赖项"部分中声明休眠依赖项:

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>

这篇关于Maven在不同模块之间共享依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆