mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-26 07:20:09 +08:00
Fix configureJvmTarget
This commit is contained in:
parent
aaab3ae109
commit
22ab149024
@ -90,7 +90,6 @@ allprojects {
|
|||||||
configureMppShadow()
|
configureMppShadow()
|
||||||
configureEncoding()
|
configureEncoding()
|
||||||
configureKotlinTestSettings()
|
configureKotlinTestSettings()
|
||||||
configureKotlinCompilerSettings()
|
|
||||||
configureKotlinExperimentalUsages()
|
configureKotlinExperimentalUsages()
|
||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||||
|
*
|
||||||
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
|
*
|
||||||
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||||
|
*/
|
||||||
|
|
||||||
@file:Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
@file:Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
||||||
|
|
||||||
import org.gradle.api.JavaVersion
|
import org.gradle.api.JavaVersion
|
||||||
@ -7,7 +16,7 @@ import org.gradle.api.tasks.compile.JavaCompile
|
|||||||
import org.gradle.api.tasks.testing.Test
|
import org.gradle.api.tasks.testing.Test
|
||||||
import org.gradle.kotlin.dsl.*
|
import org.gradle.kotlin.dsl.*
|
||||||
import org.jetbrains.kotlin.gradle.dsl.*
|
import org.jetbrains.kotlin.gradle.dsl.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||||
|
|
||||||
@ -18,23 +27,36 @@ fun Project.useIr() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE") // or error
|
|
||||||
fun Project.configureJvmTarget() {
|
fun Project.configureJvmTarget() {
|
||||||
tasks.withType(KotlinJvmCompile::class.java) {
|
val defaultVer = JavaVersion.VERSION_1_8
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlinTargets.orEmpty().filterIsInstance<KotlinJvmTarget>().forEach { target ->
|
tasks.withType(KotlinJvmCompile::class.java) {
|
||||||
target.compilations.all {
|
kotlinOptions.languageVersion = "1.4"
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
kotlinOptions.jvmTarget = defaultVer.toString()
|
||||||
kotlinOptions.languageVersion = "1.4"
|
kotlinOptions.freeCompilerArgs += "-Xjvm-default=all"
|
||||||
}
|
|
||||||
target.testRuns["test"].executionTask.configure { useJUnitPlatform() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extensions.findByType(JavaPluginExtension::class.java)?.run {
|
extensions.findByType(JavaPluginExtension::class.java)?.run {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = defaultVer
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = defaultVer
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinTargets.orEmpty().filterIsInstance<KotlinJvmTarget>().forEach { target ->
|
||||||
|
when (target.attributes.getAttribute(KotlinPlatformType.attribute)) { // mirai does magic, don't use target.platformType
|
||||||
|
KotlinPlatformType.androidJvm -> {
|
||||||
|
target.compilations.all {
|
||||||
|
/*
|
||||||
|
* Kotlin JVM compiler generates Long.hashCode witch is available since API 26 when targeting JVM 1.8 while IR prefer member function hashCode always.
|
||||||
|
*/
|
||||||
|
// kotlinOptions.useIR = true
|
||||||
|
|
||||||
|
// IR cannot compile mirai. We'll wait for Kotlin 1.5 for stable IR release.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
target.testRuns["test"].executionTask.configure { useJUnitPlatform() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,17 +99,6 @@ fun Project.configureKotlinTestSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Project.configureKotlinCompilerSettings() {
|
|
||||||
val kotlinCompilations = kotlinCompilations ?: return
|
|
||||||
for (kotlinCompilation in kotlinCompilations) with(kotlinCompilation) {
|
|
||||||
if (isKotlinJvmProject) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
this as KotlinCompilation<KotlinJvmOptions>
|
|
||||||
}
|
|
||||||
kotlinOptions.freeCompilerArgs += "-Xjvm-default=all"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val experimentalAnnotations = arrayOf(
|
val experimentalAnnotations = arrayOf(
|
||||||
"kotlin.RequiresOptIn",
|
"kotlin.RequiresOptIn",
|
||||||
"kotlin.contracts.ExperimentalContracts",
|
"kotlin.contracts.ExperimentalContracts",
|
||||||
|
Loading…
Reference in New Issue
Block a user