【问题标题】:spring boot gradle plugin in a multi module project - error finding mainClass多模块项目中的spring boot gradle插件 - 查找mainClass时出错
【发布时间】:2017-06-27 15:18:09
【问题描述】:

我使用的是Spring boot gradle插件版本1.5.1 RELEASE,如下图。构建在 webProject 时失败,抱怨缺少属性“mainClass”,并且仅在我运行“webProject:build”时才有效。这是预期的用法吗?

编辑:更新了构建脚本并从 allProjects 中删除了“spring-boot”插件。不得不在 web 项目中添加“bootRepackage”,因为它在这一步失败了——同样的错误。添加“bootRepackage”没有帮助。

buildscript {
    ext {
        springBootVersion = '1.5.1.RELEASE'
    }
    repositories {
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
    }
}

plugins {
    id 'org.springframework.boot' version '1.5.1.RELEASE'
}

defaultTasks 'clean', 'build'
apply plugin: 'java'
apply plugin: 'war'

sourceCompatibility = 1.7
targetCompatibility = 1.7

allprojects {
    apply plugin: 'java'
    //apply plugin: 'org.springframework.boot' -- Commented out based on the answer
    repositories {
        mavenLocal()
    }
    dependencies {
        compile('org.springframework.boot:spring-boot-starter-data-jpa')
        //all dependencies
    }
}

project('aProject') {
    dependencies {
        compile(project(':bProject'))

    }
}

project('webProject') {

    apply plugin: 'war'
    apply plugin: 'org.springframework.boot'
    war {
        baseName = 'webProject'
        version = '1.0.0-SNAPSHOT'
    }
    dependencies {
        compile(project(':aproject'))
        compile(project(':bProject'))
        compile 'org.springframework.boot:spring-boot-starter-tomcat'
    }
    springBoot {
        mainClass = 'com.abc.SomeApplication'
    }
bootRepackage{
    enabled = false
    mainClass = 'com.abc.SomeApplication'
}

}

【问题讨论】:

    标签: java spring gradle spring-boot build


    【解决方案1】:

    不要在主项目中使用 Spring Boot gradle 插件,只能在 webProject 子模块中使用。

    【讨论】:

    • 谢谢。我从“allprojects”战争任务中删除了插件成功,但重新打包失败并出现同样的错误。我根据您的输入更新了我的问题。谢谢
    【解决方案2】:

    我在多模块 Spring Boot 项目中遇到了类似的问题。 编译没有主类的模块 A 时。主类位于不同的模块(模块 B)中。

    我在那个模块 A 的 build.gradle 中添加了一个插件。

    apply plugin: 'application'
    
    mainClassName = "module B.ITS_MAIN_CLASS"
    

    然后就可以了。

    【讨论】:

    • 虽然这个回复解决了我的问题,但我最终还是为所有模块使用了 spring boot。也尝试了 luboskmac 的建议,但没有运气。最终没有使用bootRun。谢谢
    猜你喜欢
    • 2016-06-11
    • 2016-02-15
    • 2017-08-16
    • 2019-01-30
    • 2021-01-09
    • 2018-10-07
    • 2021-03-23
    • 2019-06-26
    • 2021-04-06
    相关资源
    最近更新 更多