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

南笙酒味 提交于 2019-12-10 23:54:31

问题


I would like to migrate a multimodule spring-boot 1.5 project to spring-boot 2.1. It is a gradle project (4.9), but somehow I dont get it solved.

With spring-boot 1.5.9 the application compiles fine and modules which are depending on other modules can also resolve the classes.

With upgrading to spring-boot 2.0 or 2.1 I am not able to get the one module resolving the classes of the other module.

In my project, the project api depends on library. Again, this build.gradle works fine for me with Spring Boot 1.5.9. I am happy with any help.

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'
    }
}

I become then a compiler issue from module *-api, which say that classes of module *-lib cannot be resolved.

Example

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

回答1:


I found the solution. The magic words are jar { enabled = true } and bootJar { enabled = false }. I put it into the project which contains the library (backend classes) for the application.

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
    }
}

The project compiles now when building it with gradle.



来源:https://stackoverflow.com/questions/54486199/multi-module-gradle-project-migrate-from-spring-boot-1-5-to-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!