I know about ``` targets { ...
# community-support
j
I know about
Copy code
targets {
                all {
                    testTask.configure {
                        javaLauncher = javaToolchains.launcherFor {
                            languageVersion = JavaLanguageVersion.of(17)
                        }
                    }
                }
            }
to run tests on a different JDK, but what if I want to compile my tests on that JDK too (but only for this suite). or at least have the runtime classpath configured for it. My use case is that i have code that compiles on java 11, but i want a test suite that pulls in some additional dependencies, which require 17 (spring boot 3), so I need to avoid the
Copy code
Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
error
well i was able to trick it by doing
Copy code
configurations.named("mySuiteRuntimeClasspath"){
    attributes {
        attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
    }
}
configurations.named("mySuiteCompileClasspath"){
    attributes {
        attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
    }
}
and to actually get compilation:
Copy code
tasks.named<JavaCompile>("compileBoot3TestJava"){
    javaCompiler.set(javaToolchains.compilerFor {
        languageVersion = JavaLanguageVersion.of(17)
    })
}
tasks.named<KotlinCompile>("compileBoot3TestKotlin"){
    kotlinJavaToolchain.toolchain.use(javaToolchains.launcherFor {
        languageVersion = JavaLanguageVersion.of(17)
    })
}
works
v
It's not so much tricking, but just configuring explicitly. 🤷‍♂️ It might be, that actually for the configurations (and maybe also the test task) the value of the "main" compile task is used, so it might be sufficient to just do the latter eventually.