Skip to content

Commit

Permalink
API 34: Change Kotlin JVM Target default.
Browse files Browse the repository at this point in the history
The new default value is null. When null, it will by default
to the Java Target compatibility. Updating AndroidJavaTargetCompatibility
will also influence the Kotlin JVM target, unless if AndroidKotlinJVMTarget
is also explicitly defined.
  • Loading branch information
breautek committed May 8, 2024
1 parent f84273a commit f2a1f19
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion framework/cdv-gradle-config-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"PACKAGE_NAMESPACE": "io.cordova.helloCordova",
"JAVA_SOURCE_COMPATIBILITY": 8,
"JAVA_TARGET_COMPATIBILITY": 8,
"KOTLIN_JVM_TARGET": "1.8"
"KOTLIN_JVM_TARGET": null
}
28 changes: 28 additions & 0 deletions templates/project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ android {
}

if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
if (cordovaConfig.KOTLIN_JVM_TARGET == null) {
// If the value is null, fallback to JAVA_TARGET_COMPATIBILITY,
// as they generally should be equal
def javaTarget = JavaLanguageVersion.of(cordovaConfig.JAVA_TARGET_COMPATIBILITY)
println "FALLBACK: " + javaTarget

// check if javaTarget is <= 8; if so, we need to prefix it with "1."
// Starting with 9 and later, the value can be used as is.
if (javaTarget.compareTo(JavaLanguageVersion.of(8)) <= 0) {
println "PREFIXING 1."
javaTarget = "1." + javaTarget
}

cordovaConfig.KOTLIN_JVM_TARGET = javaTarget
}

// Similar to above, check if kotlin target is <= 8, if so prefix it.
// This allows the user to use consistent set of values in config.xml
// Rather than having to be aware whether the "1."" prefix is needed.
// This check is only done if the value isn't already prefixed with 1.
if (
!cordovaConfig.KOTLIN_JVM_TARGET.startsWith("1.") &&
JavaLanguageVersion.of(cordovaConfig.KOTLIN_JVM_TARGET).compareTo(JavaLanguageVersion.of(8)) <= 0
) {
cordovaConfig.KOTLIN_JVM_TARGET = "1." + cordovaConfig.KOTLIN_JVM_TARGET
}

println "KOTLINJVMTARGET: " + cordovaConfig.KOTLIN_JVM_TARGET
kotlinOptions {
jvmTarget = cordovaConfig.KOTLIN_JVM_TARGET
}
Expand Down

0 comments on commit f2a1f19

Please sign in to comment.