How can you setup the jvm target (<https://docs.gr...
# community-support
p
How can you setup the jvm target (https://docs.gradle.org/current/userguide/toolchains.html#sec:consuming) for a specific jvm test suite? I want to create a jvm 8 project but a custom jvm test suite should depend on a jvm 21 dependency.
t
Configure the toolchain for each task that needs it (the compilation tasks if needed, and the test task). Could be something like:
Copy code
testing {
  suites {
    register<JvmTestSuite>("jdk21test") {
      project.tasks.named<JavaCompile>(sources.compileJavaTaskName) {
        // configure the JavaCompile toolchain
      }
      targets.configureEach {
        testTask {
          // configure the Test toolchain
        }
      }
    }
  }
}
(use https://docs.gradle.org/current/userguide/toolchains.html#toolchains_for_tasks to configure the toolchain for those tasks)
p
Thanks, easier than expected, except I also needed to configure the Kotlin compiler task too. But this is still boiler code, will create an issue to configure it once, like you can do with the java plugin.
👍 1