Gradle 4.7 build throw错误执行任务bootRepackage

时间:2018-05-02 07:28:30

标签: spring-boot gradle groovy build.gradle

在我现有的弹簧启动项目中执行gradle build命令时,使用较旧版本的Gradle(例如:3.4。*)可以正常运行。

但是在使用SDK将Gradle升级到最新版本(4.7)之后,它在构建时出现了抛出错误。

配置列表:

------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------

Build time:   2018-04-18 09:09:12 UTC
Revision:     b9a962bf70638332300e7f810689cb2febbd4a6c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
OS:           Linux 3.16.0-4-amd64 amd64

Spring Boot Details:

springBootVersion = '1.5.1.RELEASE'
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"

build.gradle 注意:我无法发布整个构建文件。所以给一些导入线进行分析。

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

subprojects {
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'war'
apply plugin: 'org.sonarqube'

// make sure bootRepackage is included in task graph
project.tasks.findAll { it.name.startsWith("artifactory") } .each { it.dependsOn assemble }

// so we can maintain both "normal" and "boot" jars
springBoot {
    classifier = 'boot' 
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            // from components.java

            // "boot" jar
            artifact ("$buildDir/libs/${project.name}-${version}-boot.war") { 
                classifier = 'boot' 
            }
        }
    }
}

def profiles = 'development'

bootRun {
    args = [
        "--spring.profiles.active=" + profiles
    ]
}

defaultTasks 'bootRun'

// Other tasks and dependency list 
 }

命令行输出:

  

gradle build

Task :test-service:bootRepackage FAILED 

> FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.7/userguide/command_line_interface.html#sec:command_line_warnings

3 个答案:

答案 0 :(得分:2)

Spring Boot 1.5.x only supports Gradle 2 (2.9 or later) and Gradle 3。不支持Gradle 4。

您可以坚持使用Gradle 3.x或升级到支持Gradle 4的Spring Boot 2.0.x.

答案 1 :(得分:0)

根据this question,您必须设置主要类:

bootRepackage {
    mainClass = 'your.app.MainClass' 
}

答案 2 :(得分:0)

错误明确指出 -

* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class

请检查build.gradle中是否有相似的条目

apply plugin: 'application'

mainClassName = 'com.my.MyApplication' // your application main class goes here