diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts index c4dc0ee160513..d1609ccdbd38c 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts @@ -1,4 +1,5 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.jvm.toolchain.internal.NoToolchainAvailableException import org.jetbrains.kotlin.pill.PillExtension import java.nio.file.Paths @@ -386,6 +387,12 @@ tasks.withType { systemProperty("jdk11Home", jdk11Provider.get()) systemProperty("jdk16Home", jdk16Provider.get()) systemProperty("jdk17Home", jdk17Provider.get()) + // jdk21Provider.isPresent throws NoToolchainAvailableException, so, we have to check for the exception + // Storing jdk21Provider in a field leads to "Configuration cache state could not be cached" error, + // since it tries to resolve the toolchain as well. + try { + systemProperty("jdk21Home", project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_21_0).get()) + } catch (_: NoToolchainAvailableException) {} if (mavenLocalRepo != null) { systemProperty("maven.repo.local", mavenLocalRepo) } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3IT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3IT.kt index d9f5842ec88f3..62b2d9102471b 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3IT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3IT.kt @@ -250,6 +250,36 @@ open class Kapt3IT : Kapt3BaseIT() { } } + // TODO: Remove as JDK 21 is supported on Java Toolchains + @DisplayName("Kapt is working with JDK 21") + @GradleTest + @GradleTestVersions(minVersion = TestVersions.Gradle.G_7_3) + @EnableOnJdk21 + fun doTestSimpleWithJdk21( + gradleVersion: GradleVersion + ) { + project( + "simple".withPrefix, + gradleVersion + ) { + //language=Groovy + buildGradle.appendText( + """ + | + |kotlin { + | jvmToolchain(21) + |} + """.trimMargin() + ) + + build("assemble") { + assertTasksExecuted(":kaptGenerateStubsKotlin", ":kaptKotlin") + // Check added because of https://youtrack.jetbrains.com/issue/KT-33056. + assertOutputDoesNotContain("javaslang.match.PatternsProcessor") + } + } + } + @DisplayName("KT-48402: Kapt worker classpath is using JRE classes from toolchain") @JdkVersions(versions = [JavaVersion.VERSION_16]) @GradleWithJdkTest diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/jdkConditions.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/jdkConditions.kt new file mode 100644 index 0000000000000..8bd3bc87aa3c5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/jdkConditions.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.testbase + +import org.junit.jupiter.api.extension.ConditionEvaluationResult +import org.junit.jupiter.api.extension.ExecutionCondition +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.extension.ExtensionContext + +class EnableOnJdk21Condition : ExecutionCondition { + override fun evaluateExecutionCondition(context: ExtensionContext?): ConditionEvaluationResult = + if (System.getProperty("jdk21Home") == null) { + ConditionEvaluationResult.disabled("No JDK 21 Found") + } else { + ConditionEvaluationResult.enabled("JDK 21 Found") + } +} + +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.RUNTIME) +@ExtendWith(EnableOnJdk21Condition::class) +annotation class EnableOnJdk21 \ No newline at end of file diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/util/moduleManipulationUtils.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/util/moduleManipulationUtils.kt index dc9f24be2a749..f4e7c91ab0417 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/util/moduleManipulationUtils.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/util/moduleManipulationUtils.kt @@ -15,7 +15,7 @@ val REQUIRED_PACKAGES_TO_TEST_CLASSES = mapOf( "com.sun.tools.javac.util" to "Context", "com.sun.tools.javac.file" to "CacheFSInfo", "com.sun.tools.javac.tree" to "TreeTranslator", - "com.sun.tools.javac.main" to "CommandLine", + "com.sun.tools.javac.main" to "Option", "com.sun.tools.javac.jvm" to "ClassFile", "com.sun.tools.javac.parser" to "Tokens\$TokenKind", "com.sun.tools.javac.code" to "Source",