在代码中配置spring依赖管理插件

i2loujxw  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(246)

我正在尝试在我的自定义插件中配置spring依赖管理插件,我为多个子项目应用了该插件,但不知何故,依赖项没有被配置,我的spring应用程序无法以beancreationexception启动,而如果它将其放入相应子项目的build.gradle.kts中,则一切正常。我不是gradle方面的Maven,我真的希望避免重复这种配置。
我错过什么了吗?

dependencyManagement{
    imports {
              mavenBom("org.springframework.cloud:spring-cloud-gcp-dependencies:1.2.4.RELEASE")
            }
}

我的插件:

open class SpringPlugin : Plugin<Project> {
override fun apply(project: Project) {
    project.configurePlugins()

    project.addDependencies()

    project.repositories.mavenCentral()
}

private fun Project.configurePlugins() {
    plugins.apply("org.springframework.boot")
    plugins.apply("kotlin-spring")
    plugins.apply("io.spring.dependency-management")
}

private fun Project.addDependencies() {

    extensions.configure(DependencyManagementExtension::class.java){
        imports {
            mavenBom("org.springframework.cloud:spring-cloud-gcp-dependencies:1.2.4.RELEASE")
        }
    }
    dependencies {
        // ... other dependencies not depending on spring-cloud-gcp-dependencies work fine

        add("implementation","org.springframework.cloud:spring-cloud-gcp-starter-logging")
        add("implementation","org.springframework.cloud:spring-cloud-gcp-starter-trace")
    }
    repositories {
        maven(url = "https://repo.spring.io/milestone")
        maven(url = "https://repository.jboss.org/nexus/content/repositories/public/")
    }
}

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题