这是父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>在子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>发布于 2014-09-05 06:50:49
这个问题的简单答案是,像groupId、artifactId和version这样的信息将由子节点继承。因此,唯一的需要通常是重写artifactId。
第二个答案很简单,因为通过dependencyManagement,您可以定义在您的孩子中可以使用什么,但是没有真正使用它。如果在依赖项块中删除依赖项,则将真正使用该依赖项。
当然,我可以推荐阅读关于依赖关系的文档,也可以推荐阅读关于继承的信息。
https://stackoverflow.com/questions/25678531
复制相似问题