Spring Boot Gradle多模块应用 [英] Spring Boot gradle multi module application

查看:106
本文介绍了Spring Boot Gradle多模块应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个模块的spring boot应用程序(渐变),但是在构建该应用程序时遇到了问题.以下是我的gradle

I have a spring boot application (gradle) with multi modules but having issues when I build the application. Below is my gradle

build.gradle(主应用程序)

plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'net.sagati'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    compile project(':my-pet-clinic-data')
    compile project(':my-pet-clinic-web')
}

test {
    useJUnitPlatform()
}

build.gradle-数据层.第一个模块

plugins {
    id 'java'
}

group 'net.sagati'
version '0.0.1-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'com.h2database:h2'
    runtimeOnly 'mysql:mysql-connector-java'
    annotationProcessor 'org.projectlombok:lombok'
    compileOnly 'org.projectlombok:lombok'
}
test {
    useJUnitPlatform()
}
bootJar {
    enabled = false
}

jar {
    enabled = true
}

build.gradle-Web层第二模块

plugins {
    id 'java'
}

group 'net.sagati'
version '0.0.1-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
}
test {
    useJUnitPlatform()
}
bootJar {
    enabled = false
}

jar {
    enabled = true
}

********************错误消息****************************************

********************error message ****************************************

A problem occurred evaluating project ':my-pet-clinic-data'.
> Could not find method bootJar() for arguments [build_iptt1011gxtkxqsop7ht18yc$_run_closure4@45139c47] on project ':my-pet-clinic-data' of type org.gradle.api.Project.

任何帮助将不胜感激.

更新

删除后

bootJar {
    enabled = false
}

我遇到了错误

Execution failed for task ':my-pet-clinic-data:compileJava'.
> Could not resolve all files for configuration ':my-pet-clinic-data:compileClasspath'.
   > Could not find org.projectlombok:lombok:.
     Required by:
         project :my-pet-clinic-data
   > Could not find org.springframework.boot:spring-boot-starter-data-jpa:.
     Required by:
         project :my-pet-clinic-data

推荐答案

更新的问题是由于没有任何版本的依赖关系引起的.

The updated issue is caused by not having any version for the dependencies.

在应用Spring boot Gradle插件时,它将应用Spring依赖管理插件并配置Spring boot BOM.文档中对此进行了说明.

When applying the Spring boot Gradle plugin, it applies the Spring dependency managment plugin and configures the Spring boot BOM. This is explained in the documentation.

但是,您的数据和Web项目仅应用 java 插件,因此不支持BOM.我建议您查看原生Gradle BOM支持.可以在上面链接的Spring文档的3.2节中找到具有性能成本的替代方案.

However your data and web projects only apply the java plugin and thus have no support for a BOM. I would recommend looking into the native Gradle BOM support. An alternative, with a performance cost, can be found in the Spring documentation linked above, section 3.2.

这篇关于Spring Boot Gradle多模块应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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