首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多模块Gradle项目-从Spring-Boot 1.5迁移到2.1

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

Stack Overflow用户
提问于 2019-02-02 03:42:18
回答 1查看 924关注 0票数 2

我想把一个多模块的spring-boot1.5项目迁移到spring-boot2.1。这是一个gradle项目(4.9),但不知何故我没有解决它。

使用spring-boot 1.5.9,应用程序可以很好地编译,并且依赖于其他模块的模块也可以解析类。

随着升级到spring-boot2.0或2.1,我无法获得一个模块来解析另一个模块的类。

在我的项目中,项目api依赖于库。同样,这个build.gradle在Spring Boot 1.5.9上运行得很好。有任何帮助我都很高兴。

代码语言:javascript
复制
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的类不能被解析。

示例

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-11 00:22:24

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

代码语言:javascript
复制
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构建该项目时,它会进行编译。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54486199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档