:samples-dir: /home/tcagent1/agent/work/64493a816be20d5a/promote-projects/gradle/build/git-checkout/platforms/documentation/docs/build/working/samples/install/jvm-multi-project-with-toolchains
:gradle-version: 9.2.0-rc-1

= Using toolchains Sample

[.download]
- link:zips/sample_jvm_multi_project_with_toolchains-groovy-dsl.zip[icon:download[] Groovy DSL]
- link:zips/sample_jvm_multi_project_with_toolchains-kotlin-dsl.zip[icon:download[] Kotlin DSL]

NOTE: You can open this sample in an link:{userManualPath}/gradle_ides.html#gradle_ides[IDE that supports Gradle].

This sample shows how to configure a toolchain for a JVM project in Gradle.
Your project usually targets a specific java version.
Using toolchains, it is very simple to set the required java version while Gradle handles the setting up the tasks (e.g. compile and test) accordingly.

Concretely, we add a _convention plugin_ in `buildSrc` to share the setup between multiple subprojects:

====
include::sample[dir="kotlin",files="buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kts[tags=toolchain]"]
include::sample[dir="groovy",files="buildSrc/src/main/groovy/myproject.java-conventions.gradle[tags=toolchain]"]
====

While most modules are fine with the defaults, the `list` subproject overrides the defaults as it has more specific requirements.

====
include::sample[dir="kotlin",files="list/build.gradle.kts[tags=customToolchain]"]
include::sample[dir="groovy",files="list/build.gradle[tags=customToolchain]"]
====

[listing.terminal.sample-command]
----
$ ./gradlew check

BUILD SUCCESSFUL
9 actionable tasks: 9 executed
----

For more information, see link:{userManualPath}/toolchains.html[Toolchains chapter].
