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

问题描述 投票: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依赖于库。再次,使用Spring Boot 1.5.9,这个build.gradle对我来说很好。我很满意任何帮助。

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
spring-boot gradle migration multi-module
1个回答
2
投票

我找到了解决方案。魔术词是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构建项目时,项目现在编译。

© www.soinside.com 2019 - 2024. All rights reserved.