为什么儿童POM不需要版本号?

时间:2014-09-05 04:16:48

标签: java maven maven-dependency-plugin

这是父POM文件的一部分:

 <properties>
    <hibernate.annotations.version>3.3.0.ga</hibernate.annotations.version>
    <hsqldb.version>1.8.0.7</hsqldb.version>
</properties>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.0.7</version>
        </dependency>

            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>${hibernate.annotations.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>${hibernate.annotations.version}</version>
        </dependency>

    </dependencies>
</dependencyManagement>

在Child POM中,我有两个问题: 1)为什么不必为hibernate指定版本号? 2)另外,由于hibernate已经在父POM中指定为依赖项,为什么有必要将它包含在子POM中?

感谢您的解释。

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.sonatype.mavenbook.optimize</groupId>
        <artifactId>simple-parent</artifactId>
        <version>1.0</version>
    </parent>
    <artifactId>simple-model</artifactId>
    <packaging>jar</packaging>

    <name>Chapter 8 Simple Object Model</name>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
        </dependency>

    </dependencies>
</project>

1 个答案:

答案 0 :(得分:0)

对此的简单回答是因为groupId,artifactId和version等信息将由子进程继承。 因此,唯一的需要通常是覆盖artifactId

第二个答案是简单的原因,通过dependencyManagement你可以定义你的孩子可以使用但不能真正使用它的东西。如果你在依赖关系块中取消依赖,它将被真正使用。

当然我可以推荐阅读documentation about dependencies我也可以推荐阅读information about inheritance