这些依赖项中没有版本号?

时间:2014-09-10 04:38:20

标签: maven dependency-properties

我正在阅读POM.xml文件并想知道为什么所有这些依赖项都没有版本号?

通常,在指定依赖关系时,应包含版本号。对?或者版本是完全可选的?

<dependencies>

    <!-- First declare the APIs we depend on and need for compilation. All 
        of them are provided by JBoss AS 7 -->

    <!-- Import the CDI API, we use provided scope as the API is included in 
        JBoss AS 7 -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the Common Annotations API (JSR-250), we use provided scope 
        as the API is included in JBoss AS 7 -->
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.1_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JAX-RS API, we use provided scope as the API is included 
        in JBoss AS 7 -->
    <dependency>
        <groupId>org.jboss.spec.javax.ws.rs</groupId>
        <artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JPA API, we use provided scope as the API is included in 
        JBoss AS 7 -->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the EJB API, we use provided scope as the API is included in 
        JBoss AS 7 -->
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.1_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- JSR-303 (Bean Validation) Implementation -->
    <!-- Provides portable constraints such as @Email -->
    <!-- Hibernate Validator is shipped in JBoss AS 7 -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Import the JSF API, we use provided scope as the API is included in 
        JBoss AS 7 -->
    <dependency>
        <groupId>org.jboss.spec.javax.faces</groupId>
        <artifactId>jboss-jsf-api_2.1_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Now we declare any tools needed -->

    <!-- Annotation processor to generate the JPA 2.0 metamodel classes for 
        typesafe criteria queries -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Annotation processor that raising compilation errors whenever constraint 
        annotations are incorrectly used. -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Needed for running tests (you may also use TestNG) -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- Optional, but highly recommended -->
    <!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA) 
        JPA from JUnit/TestNG -->
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>

2 个答案:

答案 0 :(得分:1)

版本号不是可选的,但您必须指定带有dependencies/dependency标签本身的版本号。

考虑一个多模块应用程序,其中很少有模块使用通用日志记录框架。在您想要升级到下一版本的日志框架时,在每个使用它的模块中声明日志框架依赖版本并在其他地方更新它会有多困难?如果操作不当,您可能会在不同的相互依赖的模块中使用不同版本的日志记录框架。这将是乏味的,这就是Maven拥有集中式依赖管理概念的原因。

使用Maven,您可以在<dependencyManagement/>部分中管理您的依赖版本号(这将在我上面的用例中的父pom中声明)。

即在你的代码库中的某个地方你应该找到依赖版本信息(如下所示)

<dependencyManagement>
  <!-- other dependencies -->
  <dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.1</scope>
   </dependency>
  <!-- other dependencies -->
</dependencyManagement>

official Maven documentation

了解详情

答案 1 :(得分:0)

是的,有一个dependencyManagement部分,但它们都没有。 $ {version.jboss.bom}在前面定义的一个属性中提供,但它不适用于任何这些属性。我找不到其他依赖管理。这是一个简单的演示,只有一个POM。

....
<version.jboss.bom>1.0.4.Final-redhat-4</version.jboss.bom>
....


<dependencyManagement> 
    <dependencies>
        <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill 
            of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) 
            of artifacts. We use this here so that we always get the correct versions 
            of artifacts. Here we use the jboss-javaee-6.0-with-tools stack (you can 
            read this as the JBoss stack of the Java EE 6 APIs, with some extras tools 
            for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate 
            stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras 
            from the Hibernate family of projects) -->
        <dependency>
            <groupId>org.jboss.bom</groupId>
            <artifactId>jboss-javaee-6.0-with-tools</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.bom</groupId>
            <artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>