mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-26 15:51:48 +00:00
Automatically detect Android Java 1.8 source+target (KT-21030)
When Android Java 8 desugaring is set as follows (or above):
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
set the Kotlin JVM target to 1.8
Issue #KT-21030 Fixed
This commit is contained in:
@@ -673,4 +673,30 @@ fun getSomething() = 10
|
||||
assertFileExists("libAndroid/build/tmp/kotlin-classes/debugUnitTest/foo/PlatformTest.class")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDetectAndroidJava8() = with(Project("AndroidProject")) {
|
||||
setupWorkingDir()
|
||||
|
||||
val kotlinJvmTarget18Regex = Regex("Kotlin compiler args: .* -jvm-target 1.8")
|
||||
|
||||
build(":Lib:assemble") {
|
||||
assertSuccessful()
|
||||
assertNotContains(kotlinJvmTarget18Regex)
|
||||
}
|
||||
|
||||
gradleBuildScript("Lib").appendText(
|
||||
"\n" + """
|
||||
android.compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build(":Lib:assemble") {
|
||||
assertSuccessful()
|
||||
assertContainsRegex(kotlinJvmTarget18Regex)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -734,6 +734,10 @@ abstract class AbstractAndroidProjectHandler<V>(private val kotlinConfigurationT
|
||||
}
|
||||
|
||||
val kotlinOptions = KotlinJvmOptionsImpl()
|
||||
project.whenEvaluated {
|
||||
applyAndroidJavaVersion(project.extensions.getByType(BaseExtension::class.java), kotlinOptions)
|
||||
}
|
||||
|
||||
kotlinOptions.noJdk = true
|
||||
ext.addExtension(KOTLIN_OPTIONS_DSL_NAME, kotlinOptions)
|
||||
|
||||
@@ -778,6 +782,13 @@ abstract class AbstractAndroidProjectHandler<V>(private val kotlinConfigurationT
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyAndroidJavaVersion(baseExtension: BaseExtension, kotlinOptions: KotlinJvmOptions) {
|
||||
val javaVersion =
|
||||
listOf(baseExtension.compileOptions.sourceCompatibility, baseExtension.compileOptions.targetCompatibility).min()!!
|
||||
if (javaVersion >= JavaVersion.VERSION_1_8)
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
private fun processVariant(
|
||||
variantData: V,
|
||||
compilation: KotlinJvmAndroidCompilation,
|
||||
|
||||
Reference in New Issue
Block a user