如果父pom具有Java EE BOM依赖性,是否应该在子pom中明确提及所有依赖关系? [英] should all dependencies be explicitily mentioned in child pom if the parent pom has Java EE BOM dependency?

查看:114
本文介绍了如果父pom具有Java EE BOM依赖性,是否应该在子pom中明确提及所有依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们为REST层,EJB层和域(实体)层分别提供了模块。



以下是对REST层的依赖: p>

 < dependency> 
< groupId> org.jboss.resteasy< / groupId>
< artifactId> resteasy-jaxrs< / artifactId>
< dependency>
< groupId> org.jboss.resteasy< / groupId>
< artifactId> resteasy-jettison-provider< / artifactId>
< /依赖关系>
< dependency>
< groupId> org.jboss.resteasy< / groupId>
< artifactId> resteasy-multipart-provider< / artifactId>
< /依赖关系>
<! - Resteasy服务器缓存 - >
< dependency>
< groupId> org.jboss.resteasy< / groupId>
< artifactId> resteasy-cache-core< / artifactId>
< /依赖关系>
< dependency>
< groupId> org.jboss.resteasy< / groupId>
< artifactId> resteasy-jackson-provider< / artifactId>
< /依赖关系>

Q1:是否存在 org.jboss.resteasy 提供所有这些?任何简化的可能性?应该明确声明所有这些依赖关系吗?如果不是的话,RestEasy默认提供了些什么?实际上,我使用JBoss AS 6,因此这些依赖关系仅用于编译时。它们的范围是,无论如何都提供。



同样适用于我们的域图层:

 < /依赖关系> 
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< scope>提供< / scope>
< /依赖关系>

< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-annotations< / artifactId>
< scope>提供< / scope>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-commons-annotations< / artifactId>
< scope>提供< / scope>
< /依赖关系>

< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< scope>提供< / scope>
< /依赖关系>

Q2 :为什么在我们的pom.xml中明确声明了这些内容?不应该依赖于hibernate为其他人提供默认值。

Q3 以下是一种有效的重构方式(使用Jboss bom)?在父pom.xml中有一个依赖项,每个模块只从父项继承。这样,孩子pom.xml简化和简短。这有什么缺点?我将获得我在上面每个REST和域层中明确提供的所有依赖项。

 < dependency> 
< groupId> org.jboss.bom.eap< / groupId>
< artifactId> jboss-javaee-6.0-with-resteasy< / artifactId>
< version> $ {jboss.bom.version}< / version>
< type> pom< / type>
< scope> import< / scope>
< /依赖关系>


解决方案

我认为这会为您提供所需的一切:

 < dependencyManagement> 
<依赖关系>
< dependency>
< groupId> org.jboss.bom< / groupId>
< artifactId> jboss-javaee-6.0-all-all< / artifactId>
< version> 1.0.7.Final< / version>
< type> pom< / type>
< scope> import< / scope>
< /依赖关系>
< /依赖关系>
< / dependencyManagement>
<依赖关系>
< dependency>
< groupId> org.jboss.spec< / groupId>
< artifactId> jboss-javaee-all-6.0< / artifactId>
< version> 3.0.3.Final< / version>
< scope>提供< / scope>
< /依赖关系>
< dependency>
< groupId> xalan< / groupId>
< artifactId> xalan< / artifactId>
< version> 2.7.2< / version>
< scope>提供< / scope>
< /依赖关系>
< /依赖关系>

您可以获得Java EE 6(所有API)中的所有内容。如果你想要一些特定于RestEasy的功能,你需要为它添加依赖关系。



Xalan依赖是因为bug而需要的,参见帖子。



对于WildFly 8.2上的Java EE 7,使用此依赖关系:

 < dependencyManagement> 
<依赖关系>
< dependency>
< groupId> org.wildfly.bom< / groupId>
< artifactId> jboss-javaee-7.0-all-all< / artifactId>
< version> 8.2.0.Final< / version>
< type> pom< / type>
< scope> import< / scope>
< /依赖关系>
< /依赖关系>
< / dependencyManagement>

<依赖关系>
< dependency>
< groupId> org.jboss.spec< / groupId>
< artifactId> jboss-javaee-all-7.0< / artifactId>
< version> 1.0.2.Final< / version>
< scope>提供< / scope>
< /依赖关系>
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< scope> test< / scope>
< /依赖关系>
< /依赖关系>


In our project, we have separate modules for REST layer, EJB layer and domain (Entity) layer.

Here is the dependency on our REST layer:

            <dependency>
               <groupId>org.jboss.resteasy</groupId>
               <artifactId>resteasy-jaxrs</artifactId>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jettison-provider</artifactId>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-multipart-provider</artifactId>
            </dependency>
            <!-- Resteasy Server Cache -->
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-cache-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jackson-provider</artifactId>
            </dependency>

Q1: Is there a single dependency of org.jboss.resteasy that provides all of these? Any possibility for simplification? should all these dependencies be explicitly declared? If not, what does RestEasy provides some by default? In fact, I use JBoss AS 6. so these dependencies are only for compile time. Their scope is provided anyway.

Same holds for our Domain layer:

</dependency>
                <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <scope>provided</scope>
        </dependency>

                <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <scope>provided</scope>
        </dependency>

                <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <scope>provided</scope>
        </dependency>

Q2: why are these declared explicitly in our pom.xml? shouldn't one dependency on hibernate provides defaults for others.

Q3 Is the following an effective way of refactoring (using Jboss bom) ? Have one dependency in parent pom.xml and each modules just inherit from parent. In this way, child pom.xml is simplified and short. what is the downside of this? will I get all the dependencies I provided explicitly in each of REST and domain layer above.

<dependency>
        <groupId>org.jboss.bom.eap</groupId>
        <artifactId>jboss-javaee-6.0-with-resteasy</artifactId>
        <version>${jboss.bom.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

解决方案

I think this will give you everything you need:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.bom</groupId>
            <artifactId>jboss-javaee-6.0-with-all</artifactId>
            <version>1.0.7.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-all-6.0</artifactId>
            <version>3.0.3.Final</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
            <version>2.7.2</version>
            <scope>provided</scope>
        </dependency>
</dependencies>

You get everything that is in Java EE 6 (all API's). If you want some functionality that is specific to RestEasy, you need to add dependencies for that.

The Xalan dependency is needed because of a bug, see this post.

For Java EE 7 on WildFly 8.2 use this dependencies:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>jboss-javaee-7.0-with-all</artifactId>
            <version>8.2.0.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-all-7.0</artifactId>
        <version>1.0.2.Final</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

这篇关于如果父pom具有Java EE BOM依赖性,是否应该在子pom中明确提及所有依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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