# Introducing Java toolchains

DevFeed: [Introducing Java toolchains](<https://devfeed.tech/articles/introducing-java-toolchains-24661.md>)

Original publisher: [Read original article](<https://blog.gradle.org/java-toolchains>)

Author: Louis Jacomet

Published: 2020-10-30T04:00:00Z

Content type: tutorial

Language: en

Sources: [The Gradle Blog](<https://devfeed.tech/sources/the-gradle-blog.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Java](<https://devfeed.tech/topics/java.md>), [toolchains](<https://devfeed.tech/topics/toolchains.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [install](<https://devfeed.tech/tags/install.md>), [installation](<https://devfeed.tech/tags/installation.md>), [java](<https://devfeed.tech/tags/java.md>), [jdk](<https://devfeed.tech/tags/jdk.md>), [project](<https://devfeed.tech/tags/project.md>), [run](<https://devfeed.tech/tags/run.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [toolchains](<https://devfeed.tech/tags/toolchains.md>)

## AI overview

This article introduces Java toolchain support in Gradle 6.7. It explains how to declare a project's required Java version in one place so Gradle can use that version for compilation, testing, documentation, and application execution, while allowing Gradle itself to run with another installed Java version. Gradle can detect suitable JDK installations and download a required JDK when necessary.

## Source excerpt

Building a Java project and running Gradle both require the installation of a JDK. Most Gradle users conveniently use the Java installation that is running Gradle to build and test their application. While this is acceptable in simple cases, there are a number of issues with this approach. For example, if a build requires the same Java version to be used on all machines, each developer needs to know about that requirement and install that version manually. It has been possible to configure Gradle to build a project with a different Java version than the one used to run Gradle. However, it has required configuring each task like compilation, test, and javadoc separately. Gradle 6.7 introduces "Java toolchain support". In a nutshell, it allows you to run Gradle with whatever version of Java you have installed, while Gradle builds the project with the version of Java declared in a single place. Gradle will automatically configure the build, detect already installed JDKs and download the required JDK if it is not already installed. No more release or sourceCompatibility tweaks, no more wiki pages describing which JDK you should install for the build to work. The advantages are tremendous, let's see how to use this! Introducing Java toolchains support Java toolchains support enables build authors to declare which Java version their project requires for compiling, testing and running their code. Project wide configuration Let's start with what you, as a build author, need to do, at the minimum: plugins { id("java-library") // or id("application") } java { toolchain { languageVersion.set(JavaLanguageVersion.of(11)) } } And that's it! What do you get with the above in Gradle 6.7? You get: All Java compilation tasks will use Java 11 to build. That means code in the main and test source sets, but also Java code in any custom source set you add, will be built with the configured Java version. All tests tasks, including the default test task and any additional custom Test task,