【问题标题】:Should you use the parent if you are using the spring platform bom?如果您使用的是弹簧平台 bom,您应该使用父级吗?
【发布时间】:2015-01-28 18:59:57
【问题描述】:

部分依赖版本不在,所以我添加了spring平台BOM,parent声明还有用吗?

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.1.RELEASE</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.spring.platform</groupId>
            <artifactId>platform-bom</artifactId>
            <version>1.1.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

【问题讨论】:

  • 我认为这很好,如果您不从事专业项目。如果要达到专业水平,那么您就不会希望将 spring-bom 作为您的父母-您将拥有自己的父母。

标签: spring maven spring-boot


【解决方案1】:

我个人更喜欢使用platform-bom 作为父母,即

<parent>
    <groupId>io.spring.platform</groupId>
    <artifactId>platform-bom</artifactId>
    <version>1.1.1.RELEASE</version>
    <relativePath />
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

这样我就不用定义spring-boot的版本号了,它会自动更新到新版本的spring平台,我不用担心任何不一致。

有关所有托管依赖项的完整列表,请参阅 http://docs.spring.io/platform/docs/1.1.1.RELEASE/reference/htmlsingle/#appendix-dependency-versions

编辑:正如 Andy Wilkinson 所指出的,spring 平台继承了spring-boot-starter-parent,因此http://docs.spring.io/spring-boot/docs/1.2.1.RELEASE/reference/htmlsingle/#using-boot-maven 中描述的所有“合理默认值”也适用。

【讨论】:

  • 另外值得注意的是platform-bom继承自spring-boot-starter-parent所以,通过使用platform-bom作为你的父级,你也继承了Boot的插件管理等。
【解决方案2】:

导入 BOM(在 dependencyManagement 部分)和使用 parent 之间有一个重要区别

dependencyManagement 中导入的 BOM 仅提供依赖项的默认值,但 Parent-way 也包括其他部分(pluginsplugin-managentdependenciesdependencyManagement...)

因此,当您删除父 spring-boot-starter-parent 时,您必须先复制您需要的 plugin-managent 内容。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-04-10
  • 2018-04-21
  • 1970-01-01
  • 2012-01-16
  • 1970-01-01
  • 1970-01-01
  • 2010-09-20
  • 1970-01-01
相关资源
最近更新 更多