Hello,
I have a Java 8 module which uses JDK8 via toolchains.
This module also has a test source set with JUnit unit tests in which I’d like to use a library (https://junit-pioneer.org) whose latest version only supports JDK11 or higher.
Is it possible to change the test source set’s toolchain to run with JDK 11?
Changing the test task’s toolchain as described in Toolchains for JVM projects does not do the trick it seems.
Thanks
Changing only the test tasks toolchain is too late, as it is not a testRuntimeOnly
dependency, but a testImplementation
dependency.
The compiler already needs to be compatible.
If you change the javaCompiler
of the compileTestJava
task to Java 11, the dependency can be resolved and compilation can succeed. You of course need the configuration on the test task too, as it is not a testCompileOnly
dependency.
Thanks @Vampire! Very clear now.
tasks.named<JavaCompile>("compileTestJava") {
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
})
}
tasks.named<Test>("test") {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(11))
})
useJUnitPlatform()
}
1 Like