我正在尝试在我的春季项目中导入 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
。