3

While executing gradle build command in my existing spring boot project which was / is building fine with older version of Gradle (For ex: 3.4.*).

But after I upgraded Gradle to latest version (4.7) using SDK, its started throw error while building.

Config List:

------------------------------------------------------------
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 Note: I can't publish whole build file. So giving some import lines to analyse.

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 
 }

Output from Command Line:

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
Satz
  • 307
  • 3
  • 19

3 Answers3

6

Spring Boot 1.5.x only supports Gradle 2 (2.9 or later) and Gradle 3. Gradle 4 is not supported.

You could either stick with Gradle 3.x or upgrade to Spring Boot 2.0.x which does support Gradle 4.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • I didnt think in this way. There is no backward compatibility!! Let me switch my gradle to lower version and try. – Satz May 02 '18 at 09:08
2

The error clearly states that -

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

Please check if you have entry similar in your build.gradle

apply plugin: 'application'

mainClassName = 'com.my.MyApplication' // your application main class goes here
Karthik R
  • 5,523
  • 2
  • 18
  • 30
  • I have seen this solution but I cannot apply this now, because I have 3 diff sub-projects under api. my point, why its not working now after I upgrade my Gradle to 4.7 – Satz May 02 '18 at 07:56
  • Try spring boot 2.0 release and check the same ? Spring boot 2.0 gradle plugin was designed for gradle 4.0 or later. Eitherways, you can mention mainclass for spring boot to run. try to mention under bootRepackage task. – Karthik R May 02 '18 at 07:59
1

According to this question, you have to set the main class :

bootRepackage {
    mainClass = 'your.app.MainClass' 
}
ToYonos
  • 16,469
  • 2
  • 54
  • 70
  • 1
    I have 3 diff sub projects under api so cannot do this change. And i dont want to do this in build.gradle because its working fine with lower gradle version. – Satz May 02 '18 at 07:58