为什么我必须添加父 pom 的依赖项?
Why I have to add dependencies with parent pom?
我有这段代码来自 pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
当我将鼠标悬停在某些依赖项上时,我收到此消息:The managed version is #someNumber The artifact is managed in org.springframework.boot:spring-boot-dependencies:2.0.3.RELEASE
。这个消息被认为是正确的吗?如果是,如果 parent
已经拥有所有依赖项,为什么我必须声明我正在使用的依赖项?
如果无论如何我都必须声明依赖项,那么 parent
有什么好处?仅用于管理依赖项的版本?
父 POM 不会(必然)告诉您的项目包含所有这些依赖项;它说如果你需要依赖项,使用这个版本。
例如,一些 Spring 引导项目完全基于消息,不需要 Web 部分——没有 MVC,没有 servlet 容器。将所有这些都包含在不需要的项目中是一种浪费。
更多信息,您可以查看the documentation for Maven dependency management。
我有这段代码来自 pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
当我将鼠标悬停在某些依赖项上时,我收到此消息:The managed version is #someNumber The artifact is managed in org.springframework.boot:spring-boot-dependencies:2.0.3.RELEASE
。这个消息被认为是正确的吗?如果是,如果 parent
已经拥有所有依赖项,为什么我必须声明我正在使用的依赖项?
如果无论如何我都必须声明依赖项,那么 parent
有什么好处?仅用于管理依赖项的版本?
父 POM 不会(必然)告诉您的项目包含所有这些依赖项;它说如果你需要依赖项,使用这个版本。
例如,一些 Spring 引导项目完全基于消息,不需要 Web 部分——没有 MVC,没有 servlet 容器。将所有这些都包含在不需要的项目中是一种浪费。
更多信息,您可以查看the documentation for Maven dependency management。