Debian Codegraph @

gradle/plugins/common/src/main/kotlin/junitbuild.java-toolchain-conventions.gradle.kts

raw
1 import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
2
3 plugins {
4 id("junitbuild.build-parameters")
5 }
6
7 project.pluginManager.withPlugin("java") {
8 val defaultLanguageVersion = JavaLanguageVersion.of(17)
9 val javaLanguageVersion = buildParameters.javaToolchainVersion.map { JavaLanguageVersion.of(it) }.getOrElse(defaultLanguageVersion)
10
11 val extension = the<JavaPluginExtension>()
12 val javaToolchainService = the<JavaToolchainService>()
13
14 extension.toolchain.languageVersion = javaLanguageVersion
15
16 pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
17 configure<KotlinJvmProjectExtension> {
18 jvmToolchain {
19 languageVersion = javaLanguageVersion
20 }
21 }
22 }
23
24 tasks.withType<JavaExec>().configureEach {
25 javaLauncher = javaToolchainService.launcherFor(extension.toolchain)
26 }
27
28 tasks.withType<JavaCompile>().configureEach {
29 outputs.cacheIf { javaLanguageVersion == defaultLanguageVersion }
30 doFirst {
31 if (options.release.orNull == 8 && javaLanguageVersion.asInt() >= 20) {
32 options.compilerArgs.add(
33 "-Xlint:-options" // see https://github.com/junit-team/junit5/issues/3029
34 )
35 }
36 }
37 }
38
39 tasks.withType<GroovyCompile>().configureEach {
40 javaLauncher.set(javaToolchainService.launcherFor {
41 // Groovy does not yet support JDK 19, see https://issues.apache.org/jira/browse/GROOVY-10569
42 languageVersion = defaultLanguageVersion
43 })
44 }
45 }