From d0b59863acd47858609e6b4fa94e7013c8bfc6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Fri, 14 Mar 2025 11:55:43 +0900 Subject: [PATCH] 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 --- framework/cdv-gradle-config-defaults.json | 4 +-- templates/project/app/build.gradle | 30 ++++------------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/framework/cdv-gradle-config-defaults.json b/framework/cdv-gradle-config-defaults.json index 5340cdc0..a4ad0996 100644 --- a/framework/cdv-gradle-config-defaults.json +++ b/framework/cdv-gradle-config-defaults.json @@ -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 } diff --git a/templates/project/app/build.gradle b/templates/project/app/build.gradle index 5ff337f1..ec46304c 100644 --- a/templates/project/app/build.gradle +++ b/templates/project/app/build.gradle @@ -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) } }