【问题标题】:Can I easily replace spring-boot-starter by spring-boot to avoid use of spring-boot-starter-parent?我可以通过 spring-boot 轻松替换 spring-boot-starter 以避免使用 spring-boot-starter-parent 吗?
【发布时间】:2018-10-15 14:49:57
【问题描述】:

我想使用 spring-boot-starter,但这意味着我必须使用“spring-boot-starter-parent”pom,并且不能使用公司范围内使用的 root pom。

Spring-boot-starter 在管理依赖和插件时具有巨大的优势。但这与我们公司广泛使用的 root pom 的优势相矛盾。

使用 spring-boot-starter 还有其他优势吗? 有没有一种简单的方法可以只使用 spring-boot 而没有 spring-boot-starter?

【问题讨论】:

    标签: java spring maven spring-boot


    【解决方案1】:

    将所需版本的spring-boot-starter-parent 作为父级添加到您公司的根 pom.xml 文件中。

    • 这样,spring-boot 管理您所有项目的所有依赖项。

    • 贵公司的 parent-pom 可以拥有自己的 <dependencyManagement> 来覆盖和管理任何内部或第三方依赖项。

    • plugin management 这样更干净。您可以在项目和父级定义自己的阶段。

    【讨论】:

      【解决方案2】:

      如果您不想使用spring-boot-starter-parent,您仍然可以通过使用scope=import 依赖项来保持依赖项管理(但不是插件管理)的好处,如下所示:

      <dependencyManagement>
              <dependencies>
              <dependency>
                  <!-- Import dependency management from Spring Boot -->
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-dependencies</artifactId>
                  <version>2.0.1.RELEASE</version>
                  <type>pom</type>
                  <scope>import</scope>
              </dependency>
          </dependencies>
      </dependencyManagement>
      

      here 您可以在 Spring 文档中找到相应的部分,了解更多详细信息。

      【讨论】:

      • 尝试这个我最终得到这个警告:'dependencies.dependency.scope' for org.springframework.boot:spring-boot-starter-parent:pom 必须是 [提供,编译,运行时之一, test, system] 但是是“导入”。 @ 第 26 行,第 17 列强烈建议修复这些问题,因为它们会威胁您构建的稳定性。
      • @fancyJaneDo 你还在引用“spring-boot-starter-parent”工件。您需要根据此答案和链接的 Spring 文档使用“spring-boot-dependencies”工件
      猜你喜欢
      • 2014-04-07
      • 2016-01-29
      • 1970-01-01
      • 2015-07-07
      • 2023-04-04
      • 2017-09-17
      • 2020-05-23
      • 2019-10-28
      • 2022-07-30
      相关资源
      最近更新 更多