如果父 pom 具有 Java EE BOM 依赖项,是否应在子 pom 中明确提及所有依赖项?

should all dependencies be explicitily mentioned in child pom if the parent pom has Java EE BOM dependency?

在我们的项目中,我们有用于 REST 层、EJB 层和领域(实体)层的独立模块。

这里是我们 REST 层的依赖:

            <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: 是否有 org.jboss.resteasy 的单一依赖项提供所有这些?任何简化的可能性?是否应该显式声明所有这些依赖项?如果没有,RestEasy 默认提供了什么?事实上,我使用 JBoss AS 6. 所以这些依赖项仅用于编译时。反正他们的范围是provided

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

</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:为什么要在我们的pom.xml中明确声明这些?对 hibernate 的一种依赖不应该为其他人提供默认值。

Q3 以下是一种有效的重构方式(使用 Jboss bom)吗?在父 pom.xml 中有一个依赖项,每个模块都只是从父继承。这样,childpom.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>
    </dependency>

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

<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>

您将获得 Java EE 6 中的所有内容(全部 API)。如果你想要一些特定于 RestEasy 的功能,你需要为此添加依赖项。

由于存在错误,需要 Xalan 依赖项,请参阅 this post。

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

<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>