Change logic of applying JVM target from AGP options
Now that the default JVM target is 1.8, we have to add the JVM target 1.6 explicitly if the Android project is configured with source/target 1.6, and not do anything if it's configured with 1.8. #KT-31027
This commit is contained in:
+17
-17
@@ -867,21 +867,7 @@ fun getSomething() = 10
|
||||
fun testDetectAndroidJava8() = with(Project("AndroidProject")) {
|
||||
setupWorkingDir()
|
||||
|
||||
val kotlinJvmTarget18Regex = Regex("Kotlin compiler args: .* -jvm-target 1.8")
|
||||
|
||||
gradleBuildScript("Lib").appendText(
|
||||
"\n" + """
|
||||
android.compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_6
|
||||
targetCompatibility JavaVersion.VERSION_1_6
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build(":Lib:assembleDebug", "-Pkotlin.setJvmTargetFromAndroidCompileOptions=true") {
|
||||
assertSuccessful()
|
||||
assertNotContains(kotlinJvmTarget18Regex)
|
||||
}
|
||||
val kotlinJvmTarget16Regex = Regex("Kotlin compiler args: .* -jvm-target 1.6")
|
||||
|
||||
gradleBuildScript("Lib").appendText(
|
||||
"\n" + """
|
||||
@@ -892,14 +878,28 @@ fun getSomething() = 10
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build(":Lib:assembleDebug", "-Pkotlin.setJvmTargetFromAndroidCompileOptions=true") {
|
||||
assertSuccessful()
|
||||
assertNotContains(kotlinJvmTarget16Regex)
|
||||
}
|
||||
|
||||
gradleBuildScript("Lib").appendText(
|
||||
"\n" + """
|
||||
android.compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_6
|
||||
targetCompatibility JavaVersion.VERSION_1_6
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build("clean", ":Lib:assembleDebug") {
|
||||
assertSuccessful()
|
||||
assertNotContains(kotlinJvmTarget18Regex)
|
||||
assertNotContains(kotlinJvmTarget16Regex)
|
||||
}
|
||||
|
||||
build(":Lib:assembleDebug", "-Pkotlin.setJvmTargetFromAndroidCompileOptions=true") {
|
||||
assertSuccessful()
|
||||
assertContainsRegex(kotlinJvmTarget18Regex)
|
||||
assertContainsRegex(kotlinJvmTarget16Regex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -950,9 +950,9 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationTool
|
||||
|
||||
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"
|
||||
minOf(baseExtension.compileOptions.sourceCompatibility, baseExtension.compileOptions.targetCompatibility)
|
||||
if (javaVersion == JavaVersion.VERSION_1_6)
|
||||
kotlinOptions.jvmTarget = "1.6"
|
||||
}
|
||||
|
||||
private fun preprocessVariant(
|
||||
|
||||
Reference in New Issue
Block a user