Could not target platform 'Java SE 11' using tool chain 'JDK 8 1.8'
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
This error means the build is trying to compile or run tasks for Java 11 while the selected toolchain is still JDK 8. A JDK 8 compiler can produce Java 8 bytecode, but it cannot target Java 11 because it does not understand the newer platform level, APIs, or module-era compilation rules.
Why the Error Happens
In Gradle and similar build tools, there are two separate ideas:
- The Java version your project targets.
- The JDK actually used to compile and run build tasks.
If the build says "target Java 11" but the available compiler is JDK 8, the request is impossible. That is the situation behind messages like:
The fix is not to tweak one flag and hope. The fix is to give the build a JDK that can actually compile for the requested level.
The Modern Gradle Fix: Configure a Toolchain
If you are using Gradle with Java toolchains, declare the required version explicitly:
With Groovy DSL:
This tells Gradle to use a Java 11 toolchain for compilation and related tasks. If toolchain auto-provisioning is enabled and supported by your Gradle version, Gradle can often download a matching JDK automatically.
If You Need Newer JDK to Build Older Bytecode
A common variation is wanting to build with a modern JDK but emit older-compatible bytecode. That is where --release or options.release comes in.
For example, compile with Java 17 tools but target Java 11 bytecode:
What does not work is the reverse. JDK 8 cannot compile for Java 11.
Check What Gradle Is Actually Using
Before changing the build, inspect the runtime and toolchain situation:
If javac reports 1.8, that confirms the core problem. In older builds without toolchain support, you may need to set JAVA_HOME to a JDK 11 installation before running Gradle:
On Windows PowerShell:
Watch the Gradle Version Too
Java toolchains are a Gradle feature, so older Gradle versions may not support the configuration style you see in current documentation. If the project is old, you may need either:
- A newer Gradle wrapper with toolchain support.
- A correctly configured
JAVA_HOMEthat points to JDK 11 or newer.
The important part is that the actual compiler used by the build must be new enough for the target platform.
Common Pitfalls
- Confusing
sourceCompatibilityortargetCompatibilitywith the actual installed JDK. - Assuming JDK 8 can emit Java 11 bytecode. It cannot.
- Running Gradle with one JDK while the project expects another.
- Copying toolchain config into an old Gradle version that does not support it.
- Using a JRE instead of a full JDK when compilation tasks need
javac.
Summary
- The error means the build wants Java 11 but only has JDK 8 available as the toolchain.
- The real fix is to compile with JDK 11 or newer.
- In Gradle, the best solution is usually a declared Java toolchain.
- If needed, use a newer JDK plus
options.releaseto target older bytecode levels. - Verify
java,javac, and Gradle versions before changing build files blindly.
Related reading
- Could not write JSON Infinite recursion StackOverflowError; nested exception spring boot
- CountDownLatch vs. Semaphore
- Create a custom event in Java
- Create a GUID / UUID in Java
- Create a new instance of component in Spring Boot/Framework
- Create instance of generic type in Java?
- Create instance of generic type whose constructor requires a parameter?
- Create spring repository without entity

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.