gradle 无法解析的符号:mainClassName

n6lpvg4x  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(193)

我有一个带有以下build.gradle的SpringBoot项目:

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"
}

当我运行Gradle Wrapper任务时,我收到以下错误:“未解析的引用:主类名”
这发生在我将SpringBoot从版本2.2更新到2.7,并将Gradle从版本5更新到版本6.9.3之后
在以前的配置中,项目可以很好地编译。对于这个新的配置,我还需要做什么调整吗?
有谁能给予个建议吗?

deikduxw

deikduxw1#

在Springboot 2.4中,他们更改了主classname属性的名称和类型,请参见Springboot 2.4发行说明中的:
您需要更新生成脚本,如下所示:

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

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

相关问题