【问题标题】:Gradle 4.7 build throw error executing task bootRepackageGradle 4.7构建抛出错误执行任务bootRepackage
【发布时间】:2018-10-12 05:50:35
【问题描述】:

在我现有的 spring boot 项目 中执行 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 详细信息:

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 构建

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

【问题讨论】:

  • 而错误是....?
  • @ToYonos 刚刚更新.. 抱歉
  • 您的所有子项目是否都包含一个 Spring Boot 应用程序(通常是一个带有 @SpringBootApplication 注释的类和一个 main 方法)?如果他们不这样做,那么您应该只将 Spring Boot 插件应用于这样做的项目。
  • @AndyWilkinson 是的,所有子项目都包含单独的 Main 类。

标签: spring-boot gradle groovy build.gradle


【解决方案1】:

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。

【讨论】:

  • 我没有这样想。没有向后兼容性!!让我将我的 gradle 切换到较低版本并尝试。
【解决方案2】:

错误清楚地表明 -

* 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

【讨论】:

  • 我已经看到了这个解决方案,但我现在无法应用它,因为我在 api 下有 3 个 diff 子项目。我的观点,为什么在我将 Gradle 升级到 4.7 后它现在不工作了
  • 尝试 spring boot 2.0 版本并检查是否相同? Spring boot 2.0 gradle 插件是为 gradle 4.0 或更高版本设计的。无论哪种方式,您都可以提及 mainclass 以供 Spring Boot 运行。尝试在 bootRepackage 任务下提及。
【解决方案3】:

根据this question,你要设置主类:

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

【讨论】:

  • 我在 api 下有 3 个 diff 子项目,所以无法进行此更改。而且我不想在 build.gradle 中这样做,因为它在较低的 gradle 版本下工作正常。
猜你喜欢
  • 2018-12-10
  • 2015-12-30
  • 1970-01-01
  • 1970-01-01
  • 2015-09-29
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多