使用gradle BOM和spring-boot(多模块应用程序)的方法更好

问题描述 投票:0回答:1

我使用Gradle来构建我的spring-boot应用程序。我想要什么?

我有一个多模块应用程序,其中一些模块是spring-boot应用程序。我想在父项目的Gradle文件中获取BOM spring依赖项,并使用没有版本的所有库。

现在我有下一个配置:

 buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }

apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

我在每个模块中复制了这段代码。我读了Gradle documentation and看到这个:

插件本身不再自动应用Spring Dependency Management插件。相反,它确实对使用spring-boot-dependencies BOM(物料清单)应用和配置的Spring Dependency Management插件作出反应。我们将在本文后面详细介绍BOM支持。)

以下是一个例子:

plugins {
    id 'java'
    id 'com.gradle.build-scan' version '1.16'
    id 'org.springframework.boot' version '2.0.5.RELEASE'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE'
...

我糊涂了。什么变体更好?我尝试更改我的代码,就像这个文档,我得到一个错误:

> Could not resolve all files for configuration ':my-server:compileClasspath'.
   > Could not find org.springframework.boot:spring-boot-starter-data-jpa:.
     Required by:
         project :my-server
   > Could not find org.springframework.boot:spring-boot-starter-cache:.
     Required by:
         project :my-server
   > Could not find org.springframework.boot:spring-boot-configuration-processor:.
     Required by:
         project :my-server
   > Could not find org.hibernate:hibernate-jpamodelgen:.
     Required by:
         project :my-server
   > Could not find org.projectlombok:lombok:.
     Required by:
         project :my-server
   > Could not find org.springframework.kafka:spring-kafka:.
     Required by:
         project :my-server
spring-boot gradle gradle-plugin spring-boot-gradle-plugin maven-bom
1个回答
0
投票

您仍然需要为依赖项定义repositories。将以下行添加到build.gradle。

repositories {
    mavenCentral()
}
© www.soinside.com 2019 - 2024. All rights reserved.