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].
