是不是可以使用Spring Boot Gradle插件来限制依赖管理到特定的配置?

huangapple go评论50阅读模式
英文:

Is it possible to restrict dependency management to a given configuration with the Spring Boot Gradle Plugin

问题

我正在使用 spring-boot-gradle-plugin:2.4.13 与 Gradle 5.6.4。

我们正在使用 dependency-management-plugin 的 "configurations" 块来限制依赖管理到一组特定的 Gradle 配置,如下所示:

apply plugin: "io.spring.dependency-management"
dependencyManagement {
    configurations(compile, compileOnly, runtime, annotationProcessor) {
        imports {
            mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
        }
    }
}

这按预期工作,但是,如果我们随后应用 org.springframework.boot 插件,那么指定的配置将被忽略,依赖管理将用于所有配置。

我看到 spring-boot-gradle-plugin 在应用 DependencyManagementPlugin 时执行了 此操作,这似乎可能是问题所在。

因此,我想知道是否可能应用 org.springframework.boot 插件,以便依赖管理仅在特定一组配置中使用。

英文:

I am using spring-boot-gradle-plugin:2.4.13 with Gradle 5.6.4.

We are using the "configurations" block of the dependency-management-plugin to limit dependency management to a set of specific Gradle configurations, as shown below

apply plugin: "io.spring.dependency-management"
dependencyManagement {
    configurations(compile,compileOnly, runtime,annotationProcessor) {
        imports {
            mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
        }
    }
}

This works as expected however, if we subsequently apply the org.springframework.boot plugin, then the specified configurations are ignored and dependency management is used for all configurations.

I see that the spring-boot-gradle-plugin performs this action in response to the DependencyManagementPlugin being applied, which seems like it might be the issue.

So I would like to know whether it is possible to apply the org.springframework.boot plugin such that dependency management is only used within a specific set of configurations.

答案1

得分: 0

我不认为你想做的事情是可能的。我在Spring Boot Gradle插件的文档中没有看到允许这种类型自定义的内容。话虽如此,我认为你唯一的选择是不使用Spring Dependency Management插件,而是使用Gradle平台。这将允许你执行以下操作:

dependencies {
    implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
}

这将允许你应用Spring Boot Gradle插件,但可以选择将其BOM应用于哪些配置。你可以在这里找到更多信息:https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#managing-dependencies.gradle-bom-support。

英文:

I don't think what you want to do is possible. I don't see anything in the documentation of the Spring Boot Gradle plugin that allows this type of customization. With that said, I think your only option is to not use the Spring Dependency Management plugin and use Gradle platform instead. This will allow you do do the following:

dependencies {
    implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
}

https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#managing-dependencies.gradle-bom-support

This will allow you to apply the Spring Boot Gradle plugin, but choose which configurations to apply its BOM it to.

huangapple
  • 本文由 发表于 2023年7月6日 20:55:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定