Search code examples
springgradle

Gradle build failed: Main class name has not been configured and it could not be resolved


I am building a RESTful web service with Spring by following this guide. I am using gradle to build the app but my build is failing.

I used the "build gradle" command on a Windows 10 machine.

This is the gradle code:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-rest-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

I am getting the following error:

Execution failed for task ':bootJar'.

Main class name has not been configured and it could not be resolved


Solution

  • When building a multi-module project which includes a module outside of the springboot project, then the module's build.gradle must contain:

    bootJar {
        enabled = false
    }
    
    jar {
        enabled = true
    }