多模块Gradle项目-从Spring-Boot 1.5迁移到2.1 [英] Multi-Module Gradle project - Migrate from Spring-Boot 1.5 to 2.1

查看:213
本文介绍了多模块Gradle项目-从Spring-Boot 1.5迁移到2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

通过升级到spring-boot 2.0或2.1,我无法使一个模块解析另一个模块的类.

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.

在我的项目中,项目api取决于库.同样,这个build.gradle对Spring Boot 1.5.9来说对我来说很好用.我很乐意提供帮助.

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

然后我成为模块*-api的编译器问题,该问题表明模块*-lib的类无法解析.

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

示例

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 }.我将其放入包含应用程序库(后端类)的项目中.

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

使用gradle构建项目时,现在可以编译该项目.

The project compiles now when building it with gradle.

这篇关于多模块Gradle项目-从Spring-Boot 1.5迁移到2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆