代码之家  ›  专栏  ›  技术社区  ›  bajji

Spring Boot gradle多模块应用程序

  •  0
  • bajji  · 技术社区  · 6 年前

    我有一个多模块的spring boot应用程序(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
    }
    

    ********************错误信息****************************************

    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
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   Louis Jacomet    6 年前

    更新的问题是由于没有依赖项的任何版本造成的。

    在应用Spring boot Gradle插件时,它会应用Spring依赖管理插件并配置Spring boot BOM。这在 documentation .

    但是,您的数据和web项目仅适用于 java 插件,因此不支持BOM。我建议查看 native Gradle BOM support 一种具有性能成本的替代方案可以在上面链接的Spring文档第3.2节中找到。