NOTE: You can open this sample inside an IDE using the https://www.jetbrains.com/help/idea/gradle.html#gradle_import_project_start[IntelliJ native importer] or https://projects.eclipse.org/projects/tools.buildship[Eclipse Buildship].

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="groovy",files="buildSrc/src/main/groovy/myproject.java-conventions.gradle[tags=toolchain]"]
include::sample[dir="kotlin",files="buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kts[tags=toolchain]"]
====

While most modules are fine with the defaults, the one of our modules overrides the defaults as it has more specific requirements.

====
include::sample[dir="groovy",files="list/build.gradle[tags=customToolchain]"]
include::sample[dir="kotlin",files="list/build.gradle.kts[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].
