gradle - 导入协程-常见会导致错误 “Cannot inline bytecode build with JVM target 1.8 into…”。即使使用明确指定的jvmTarget

标签 gradle kotlin jvm kotlin-coroutines

我正在尝试在 Spring 项目中导入Kotlin协程。

我的build.gradle文件中包含以下几行:

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

但是无论如何,当我使用implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1'导入通用程序时,我得到了错误:Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option
如果删除implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1',则项目构建良好。

如何导入Kotlin协程?

附言我试过了
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions { 
        apiVersion = "1.3"
        languageVersion = "1.3"
        jvmTarget = "1.8"
    }
}

完整的build.gradle文件:
buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
        classpath("org.jetbrains.kotlin:kotlin-noarg:1.3.20")
        classpath("org.jetbrains.kotlin:kotlin-allopen:1.3.20")
    }
}

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'org.jetbrains.kotlin.jvm' version '1.3.20'
    id 'org.jetbrains.kotlin.plugin.spring' version '1.3.20'
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'kotlin-jpa'

allOpen {
    annotation("javax.persistence.Entity")
    annotation("javax.persistence.MappedSuperclass")
    annotation("javax.persistence.Embeddable")
}

group = 'com.liberaid'
version = '0.0.1'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { url "https://dl.bintray.com/rookies/maven"  }
}

dependencies {
    def withoutX = {
        exclude group: 'org.slf4j', module: 'slf4j-log4j12'
        exclude group: 'org.slf4j', module: 'slf4j-jdk14'
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }

    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'
    implementation 'commons-net:commons-net:3.6'
    implementation 'net.lingala.zip4j:zip4j:1.3.2'
    implementation 'org.apache.pdfbox:pdfbox:2.0.1'

    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'mysql:mysql-connector-java:+'

    /* Json parsers */
    implementation 'org.json:json:+'
    implementation 'com.google.code.gson:gson:+'

    /* HTML parser */
    implementation 'org.jsoup:jsoup:1.11.3'

    /* GROBID - citation parser */
    implementation 'org.grobid:grobid-core:0.5.4', withoutX
    implementation 'org.grobid:grobid-trainer:0.5.4', withoutX

    /* Kotlin coroutines */
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1'

    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

最佳答案

依赖性org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1错误。

请改用org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1

关于gradle - 导入协程-常见会导致错误 “Cannot inline bytecode build with JVM target 1.8 into…”。即使使用明确指定的jvmTarget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55319579/

相关文章:

android - 三星 Android 10 BLE MTU>23 问题

java - 安装了非法 key 大小 Jvm 8 但项目源/二进制文件是 jdk7

java - Kotlin作用域函数其实是java匿名类?

java - 调度线程时的 JVM 公平性

Groovy 'No signature of method' 针对委托(delegate)运行关闭

java - Activity 内的 Android 上下文可以是静态的吗?

java - Gradle / eclipse : Different behavior of german "Umlaute" when using equality?

android - 如何在官方 Youtube 应用程序中检测当前正在播放的视频

spring - 如何在bootJar中有条件地启用launchScript()?

eclipse - Spring项目的初始设置