我有这段来自 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>
当我将鼠标悬停在某些依赖项上时,我收到以下消息:托管版本为#someNumber The artifact is managed in org.springframework.boot:spring-boot-dependencies:2.0.3.RELEASE
。这个消息被认为是正确的吗?如果是,如果 parent
已经拥有所有依赖项,为什么我必须声明我正在使用的依赖项?
如果无论如何我都必须声明我的依赖项,那么拥有一个parent
有什么好处?仅用于管理依赖项的版本?
最佳答案
父 POM 不会(必然)告诉您的项目包含所有这些依赖项;它说如果您需要依赖项,请使用此版本。
例如,一些 Spring Boot 项目完全基于消息,不需要 Web 部分——没有 MVC,没有 servlet 容器。将所有这些都包含在不需要的项目中是一种浪费。
更多信息,您可以查看the documentation for Maven dependency management .
关于java - 为什么我必须添加父 pom 的依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51757324/