代码之家  ›  专栏  ›  技术社区  ›  Shane Rowatt

使用Gradle 5.1“实现平台”代替Spring依赖关系管理插件

  •  2
  • Shane Rowatt  · 技术社区  · 6 年前

    我已经编写了一个Gradle插件,其中包含一系列常见的设置配置,因此我们所有的项目都只需要应用该插件和一组依赖项。它使用Spring依赖关系管理插件为Spring设置BOM导入,如下代码段所示:

    trait ConfigureDependencyManagement {
        void configureDependencyManagement(final Project project) {
            assert project != null
    
            project.apply(plugin: "io.spring.dependency-management")
    
            final DependencyManagementExtension dependencyManagementExtension = project.extensions.findByType(DependencyManagementExtension)
            dependencyManagementExtension.imports {                 
                mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE"
            }
         }
      }
    

    trait ConfigureDependencyManagement {
        void configureDependencyManagement(final Project project) {
            assert project != null
    
            project.dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE")
        }
    }
    

    不幸的是,更改意味着这些BOM表定义的依赖项都没有被导入,并且我在构建项目时会遇到类似的错误?

    项目:

    找不到org.springframework.boot:spring启动程序数据jpa:。 要求:

    要求: 项目:

    我认为Gradle 5.1不再需要Spring依赖关系管理插件,如果是这样的话,那么我是否错过了一些可以让它工作的东西?

    1 回复  |  直到 3 年前
        1
  •  7
  •   Louis Jacomet    6 年前

    Gradle 5中的平台支持可以替代Spring依赖关系管理插件来使用BOM。但是,Spring插件提供了Gradle支持中未涵盖的功能。

    关于您的问题,问题来自以下方面:

    project.dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE")
    

    Dependency ,它仍然需要添加到配置中。通过这样做:

    def platform = project.dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE")
    project.dependencies.add("configurationName", platform)
    

    哪里 configurationName