Skip to content

Commit c66b789

Browse files
committed
KAPT3: Use another class in com.sun.tools.javac.main
Instead of CommandLine use Option, since CommandLine was moved or removed from JDK 21. #KT-60507 Fixed
1 parent d4ce8c7 commit c66b789

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2+
import org.gradle.jvm.toolchain.internal.NoToolchainAvailableException
23
import org.jetbrains.kotlin.pill.PillExtension
34
import java.nio.file.Paths
45

@@ -386,6 +387,12 @@ tasks.withType<Test> {
386387
systemProperty("jdk11Home", jdk11Provider.get())
387388
systemProperty("jdk16Home", jdk16Provider.get())
388389
systemProperty("jdk17Home", jdk17Provider.get())
390+
// jdk21Provider.isPresent throws NoToolchainAvailableException, so, we have to check for the exception
391+
// Storing jdk21Provider in a field leads to "Configuration cache state could not be cached" error,
392+
// since it tries to resolve the toolchain as well.
393+
try {
394+
systemProperty("jdk21Home", project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_21_0).get())
395+
} catch (_: NoToolchainAvailableException) {}
389396
if (mavenLocalRepo != null) {
390397
systemProperty("maven.repo.local", mavenLocalRepo)
391398
}

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kapt3IT.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,36 @@ open class Kapt3IT : Kapt3BaseIT() {
250250
}
251251
}
252252

253+
// TODO: Remove as JDK 21 is supported on Java Toolchains
254+
@DisplayName("Kapt is working with JDK 21")
255+
@GradleTest
256+
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_3)
257+
@EnableOnJdk21
258+
fun doTestSimpleWithJdk21(
259+
gradleVersion: GradleVersion
260+
) {
261+
project(
262+
"simple".withPrefix,
263+
gradleVersion
264+
) {
265+
//language=Groovy
266+
buildGradle.appendText(
267+
"""
268+
|
269+
|kotlin {
270+
| jvmToolchain(21)
271+
|}
272+
""".trimMargin()
273+
)
274+
275+
build("assemble") {
276+
assertTasksExecuted(":kaptGenerateStubsKotlin", ":kaptKotlin")
277+
// Check added because of https://youtrack.jetbrains.com/issue/KT-33056.
278+
assertOutputDoesNotContain("javaslang.match.PatternsProcessor")
279+
}
280+
}
281+
}
282+
253283
@DisplayName("KT-48402: Kapt worker classpath is using JRE classes from toolchain")
254284
@JdkVersions(versions = [JavaVersion.VERSION_16])
255285
@GradleWithJdkTest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
package org.jetbrains.kotlin.gradle.testbase
7+
8+
import org.junit.jupiter.api.extension.ConditionEvaluationResult
9+
import org.junit.jupiter.api.extension.ExecutionCondition
10+
import org.junit.jupiter.api.extension.ExtendWith
11+
import org.junit.jupiter.api.extension.ExtensionContext
12+
13+
class EnableOnJdk21Condition : ExecutionCondition {
14+
override fun evaluateExecutionCondition(context: ExtensionContext?): ConditionEvaluationResult =
15+
if (System.getProperty("jdk21Home") == null) {
16+
ConditionEvaluationResult.disabled("No JDK 21 Found")
17+
} else {
18+
ConditionEvaluationResult.enabled("JDK 21 Found")
19+
}
20+
}
21+
22+
@Target(AnnotationTarget.FUNCTION)
23+
@Retention(AnnotationRetention.RUNTIME)
24+
@ExtendWith(EnableOnJdk21Condition::class)
25+
annotation class EnableOnJdk21

plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/util/moduleManipulationUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ val REQUIRED_PACKAGES_TO_TEST_CLASSES = mapOf(
1515
"com.sun.tools.javac.util" to "Context",
1616
"com.sun.tools.javac.file" to "CacheFSInfo",
1717
"com.sun.tools.javac.tree" to "TreeTranslator",
18-
"com.sun.tools.javac.main" to "CommandLine",
18+
"com.sun.tools.javac.main" to "Option",
1919
"com.sun.tools.javac.jvm" to "ClassFile",
2020
"com.sun.tools.javac.parser" to "Tokens\$TokenKind",
2121
"com.sun.tools.javac.code" to "Source",

0 commit comments

Comments
 (0)