多模块 Gradle 项目 - 从 Spring-Boot 1.5 迁移到 2.1

Multi-Module Gradle project - Migrate from Spring-Boot 1.5 to 2.1

我想将多模块 spring-boot 1.5 项目迁移到 spring-boot 2.1。这是一个 gradle 项目 (4.9),但不知何故我没有解决它。

使用 spring-boot 1.5.9 应用程序编译正常,依赖于其他模块的模块也可以解析 类.

随着升级到 spring-boot 2.0 或 2.1,我无法让一个模块解析另一个模块的 类。

在我的项目中,项目api依赖库。同样,这个 build.gradle 在 Spring Boot 1.5.9 上对我来说工作正常。我很高兴得到任何帮助。

buildscript {
    ext { springBootVersion = '1.5.9.RELEASE' }
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath "o.s.b:spring-boot-gradle-plugin:${springBootVersion}"
    }
}

allprojects {
    apply plugin: 'eclipse'
    apply plugin: 'maven'
    apply plugin: 'maven-publish'

    group = 'n.h.f.calculator'
    version = "0.1.0-SNAPSHOT"

}

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

    sourceCompatibility = JavaVersion.VERSION_1_8

    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        compile       'o.c.groovy:groovy'
        testCompile   'o.s.b:spring-boot-starter-test'
    }
}

project(':' + rootProject.name + '-library') {
    dependencies {
        compile 'org.springframework.boot:spring-boot-starter'
    }
}

project(':' + rootProject.name + '-api') {
    dependencies {
        compile project (':' + rootProject.name + '-library')
        compile         'o.s.b:spring-boot-starter-web'
    }
}

然后我成为模块 *-api 的编译器问题,它说模块 *-lib 的 类 无法解决。

例子

C:\Development\Projects\Immosoft\financial-calculator\api\src\main\groovy\net\hemisoft\financial\calculator\api\BasicApi.groovy: 7: unable to resolve class net.hemisoft.financial.calculator.library.utils.BasicCalculator
@ line 7, column 1.
import net.hemisoft.financial.calculator.library.utils.BasicCalculator

我找到了解决方案。魔法词是 jar { enabled = true }bootJar { enabled = false }。我将它放入包含应用程序库(后端 类)的项目中。

buildscript {
    ext {
        springBootVersion = '2.1.2.RELEASE'
    }
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath "o.s.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}

...

project(':' + rootProject.name + '-library') {
    dependencies {
        compile 'o.s.boot:spring-boot-starter'
    }

    jar {
        enabled = true
    }

    bootJar {
        enabled = false
    }
}

使用 gradle.

构建项目时,现在可以编译该项目