Home > front end >  Unresolved symbol:mainClassName
Unresolved symbol:mainClassName

Time:10-24

I have a SpringBoot project with the following build.gradle:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile


plugins {
    id("org.springframework.boot") version "2.7.0"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    kotlin("jvm") version "1.7.0"
    kotlin("plugin.spring") version "1.7.0"
    kotlin("plugin.jpa") version "1.6.21"
    id("org.flywaydb.flyway") version "6.4.4"
}

group = "com.planes"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.apache.tomcat.embed:tomcat-embed-jasper")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-validation")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("io.jsonwebtoken:jjwt:0.9.0")
    implementation("org.postgresql:postgresql")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("org.springframework.security:spring-security-test")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

springBoot {
    mainClassName = "com.planes.planesserver.DemoApplication"
}

When I run the Gradle Wrapper Task I get the following error: "Unresolved reference: mainClassName"

This happens after I updated SpringBoot from Version 2.2 to 2.7 and gradle from version 5 to version 6.9.3

In the previous configuration the project could compile just fine. Are there any adjustments I need to still make for this new configuration ?

Can anyone please give a suggestion ?

CodePudding user response:

In Springboot 2.4 they changed the name and type of the main classname property, see in Springboot 2.4 Release notes:

You need to update your build script as follows :

springBoot {
    // before springboot 2.4
    // mainClassName = "com.planes.planesserver.DemoApplication"

    // since springboot 2.4 : 
    mainClass.set( "com.planes.planesserver.DemoApplication")
}
  • Related