使用Gradle 5.1的“实现平台",可以使用“代替Spring Dependency Management插件 [英] Using Gradle 5.1 "implementation platform" instead of Spring Dependency Management Plugin

查看:665
本文介绍了使用Gradle 5.1的“实现平台",可以使用“代替Spring Dependency Management插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Gradle插件,其中包含许多常用的设置配置,因此我们所有的项目都只需要应用该插件和一组依赖项即可.它使用Spring Dependency Management插件为Spring设置BOM导入,如下面的代码片段所示:

I have written a Gradle Plugin that contains a bunch of common setup configuration so that all of our projects just need to apply that plugin and a set of dependencies. It uses the Spring Dependency Management Plugin to setup the BOM imports for Spring as shown in the code snippet below:

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"
        }
     }
  }

虽然在Gradle 5.1中仍然可以使用,但我想用BOM导入的新依赖机制替换Spring Dependency Management插件,所以我将上面的内容更新为:

Whilst that still works in Gradle 5.1 I wanted to replace the Spring Dependency Management Plugin with the new dependency mechanism for BOM Imports so I updated the above to now be this:

trait ConfigureDependencyManagement {
    void configureDependencyManagement(final Project project) {
        assert project != null

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

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

Unfortunately that change means none of the dependencies defined by these BOMs are being imported and I get errors like these when building projects?

找不到org.springframework.boot:spring-boot-starter-web:. 要求者: 项目:

Could not find org.springframework.boot:spring-boot-starter-web:. Required by: project :

找不到org.springframework.boot:spring-boot-starter-data-jpa:. 要求者: 项目:

Could not find org.springframework.boot:spring-boot-starter-data-jpa:. Required by: project :

找不到org.springframework.boot:spring-boot-starter-security:. 要求者: 项目:

Could not find org.springframework.boot:spring-boot-starter-security:. Required by: project :

我是否正确地认为Gradle 5.1不再需要Spring Dependency Management插件?如果是的话,我是否缺少一些可以使之起作用的东西?

Am I correct in thinking the Spring Dependency Management Plugin is no longer needed with Gradle 5.1 and if so then am I missing something for this to work?

推荐答案

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

The platform support in Gradle 5 can replace the Spring dependency management plugins for BOM consumption. However the Spring plugin offers features that are not covered by the Gradle support.

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

Regarding your issue, the problem comes from the following line:

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

这只会创建一个Dependency,它仍然需要添加到配置中.通过执行类似的操作:

This will simply create a Dependency, it still needs to be added to a configuration. by doing something like:

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

其中,configurationName是需要BOM的配置的名称.请注意,根据您的项目,您可能必须将此BOM添加到多种配置中.

where configurationName is the name of the configuration that requires the BOM. Note that you may have to add this BOM to multiple configurations, depending on your project.

这篇关于使用Gradle 5.1的“实现平台",可以使用“代替Spring Dependency Management插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆