我正在尝试将我的项目从groovy gradle dsl迁移到kotlin gradle dsl。我写了这样的代码:
buildscript {
val kotlin_version = "1.3.61"
(project.rootProject.extensions.getByName("ext") as ExtraPropertiesExtension).set("kotlin_version", kotlin_version)
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}
plugins {
java
idea
kotlin("jvm") version "1.3.72"
}
allprojects {
apply(plugin = "java")
apply(plugin = "kotlin")
apply(plugin = "idea")
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).all {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
kotlinOptions {
freeCompilerArgs = listOf("-Xjvm-default=enable")
jvmTarget = "1.8"
apiVersion = "1.3"
languageVersion = "1.3"
}
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
jcenter()
}
}
And everything works almost fine but IntelliJ IDEA highlights idea
and java
here:
plugins {
java
idea
kotlin("jvm") version "1.3.72"
}
And configure
here:
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
有错误 “无法将使用JVM target 1.8构建的字节码内联到使用JVM target 1.6构建的字节码中。请指定适当的'-jvm-target'选项”
因此,我应该在哪里指定正确的“ -jvm-target”选项,或者应该做什么?
如您所见:
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
转到应用程序级别build.gradle并插入如下所示的选项:
而且它将成功。