Kotlin:无法将使用 JVM 目标 1.8 构建的字节码内联到使用 JVM 目标 1.6 的字节代码中

ste*_*erd 5 gradle kotlin

我在尝试向我的 kotlin spring 项目添加一些依赖项时遇到问题。我使用 spring boot 初始化程序来运行一个基本项目。

我的问题:如果我取消注释 jackson 或 Koin 依赖项,那么我的构建会失败,标题中提到的是以下是 build.gradle.kts 文件:

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

plugins {
    kotlin("plugin.jpa") version "1.3.31"
    id("org.springframework.boot") version "2.2.0.M4"
    id("io.spring.dependency-management") version "1.0.7.RELEASE"
    kotlin("jvm") version "1.3.31"
    kotlin("plugin.spring") version "1.3.31"
}

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

val developmentOnly by configurations.creating
configurations {
    runtimeClasspath {
        extendsFrom(developmentOnly)
    }
}

repositories {
    mavenCentral()
    maven { url = uri("https://repo.spring.io/snapshot") }
    maven { url = uri("https://repo.spring.io/milestone") }
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
    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")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    runtimeOnly("com.h2database:h2")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
        exclude(group = "junit", module = "junit")
    }

    // jackson
    //implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.+")

    // Koin
    //implementation("org.koin:koin-core:2.0.1")

    // Koin Test
    //implementation("org.koin:koin-test:2.0.1")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

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

我已经尝试了其他人问的上一个问题的所有解决方案:Cannot inline bytecodebuilt with JVM target 1.8 into bytecode that is beingbuilt with JVM target 1.6

我已经在那里设置了 KotlinCompile jvmTarget 选项,并且它也已在我的构建设置中进行了设置。任何帮助表示感谢!

bsa*_*ner 6

很多答案都是针对 android 的 - 使用 kotlin 编写 Spring Boot 应用程序没有很好的文档记录或支持,但仍然很棒。intelij 中的此设置为我清除了此错误 - 希望它对某人有所帮助,我的 kotlin 编译器将目标设置为 1.6:

在此输入图像描述