feat!: bump java default targets to 11 (#1784)

* feat!: bump java source, target & kotlin jvm target to default 11
* chore!: remove java <= 8 logic
* refactor: setting of kotlin's jvmTarget
This commit is contained in:
エリス 2025-03-14 11:55:43 +09:00 committed by GitHub
parent 7544fdf1ed
commit d0b59863ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 27 deletions

View File

@ -13,7 +13,7 @@
"IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED": false,
"IS_GRADLE_PLUGIN_KOTLIN_ENABLED": false,
"PACKAGE_NAMESPACE": "io.cordova.helloCordova",
"JAVA_SOURCE_COMPATIBILITY": 8,
"JAVA_TARGET_COMPATIBILITY": 8,
"JAVA_SOURCE_COMPATIBILITY": 11,
"JAVA_TARGET_COMPATIBILITY": 11,
"KOTLIN_JVM_TARGET": null
}

View File

@ -261,33 +261,13 @@ 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)
// 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) {
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
}
// If KOTLIN_JVM_TARGET is null, fallback to JAVA_TARGET_COMPATIBILITY,
// as they generally should be equal
cordovaConfig.KOTLIN_JVM_TARGET = cordovaConfig.KOTLIN_JVM_TARGET ?:
cordovaConfig.JAVA_TARGET_COMPATIBILITY
kotlinOptions {
jvmTarget = cordovaConfig.KOTLIN_JVM_TARGET
jvmTarget = JavaLanguageVersion.of(cordovaConfig.KOTLIN_JVM_TARGET)
}
}