Gradle - Could not target platform: 'Java SE 8' using tool chain: 'JDK 7 (1.7)'
No time to read? Don't worry, just update Gradle to use the JDK 8. Set the JAVA_HOME
to your JDK 8 executable path, or directly in your gradle.properties
:
Replace C:/Java/jdk8
with your specific JDK 8 install location, and Gradle will target the appropriate Java version.
In IntelliJ IDEA version 2018.1.2, you can accomplish this by updating your IDE settings. Navigate to Build Tools -> Gradle -> Gradle JVM and update this to the verified JDK 1.8 installation.
Getting versions in order: Gradle, JDK, and IntelliJ
Successful builds require harmonized versions of Gradle, the JDK, and IntelliJ IDEA. How do you achieve this? Follow the guide below:
Updating Gradle's compatibility version
In your build.gradle
, ensure that sourceCompatibility
and targetCompatibility
are being set to 1.8
:
Making the best use of Gradle Wrapper
Using the Gradle Wrapper can provide a more consistent experience across teams. Run gradlew wrapper --gradle-version X.Y
to set the desired wrapper version.
IntelliJ IDEA version compatibility
- In IntelliJ, confirm the correct Gradle JVM is selected under Preferences | Build, Execution, Deployment | Build Tools | Gradle.
- If using an older IntelliJ version, it's time to hit that update button. Newer Java versions need the latest and greatest IDE version.
Fine-tuning your JDK setup
- If you're still seeing mismatches or issues even after updating JDK, take a moment to verify your project's targeting Java version.
- Not afraid of trial and error? Play around with different JDK installations by changing the JDK path in
gradle.properties
.
Keeping your properties in check
- In
gradle.properties
, erase any hardcoded properties that may cause chaos, such as an old definition fororg.gradle.java.home
.
Bridging the environment gap
- Aim for a uniform environment setup across different machines. Utilize a Docker container, a VM with the correct JDK, or stick to the Gradle Wrapper.
- When working on a multi-project setup, nip version drift in the bud by managing JDK and Gradle versions in the root
build.gradle
.
Keeping IntelliJ IDEA in good shape
- For extra performance, tweak IntelliJ configurations to use a local Gradle distribution rather than the pre-packaged version.
- Peculiarity identified - IntelliJ's Build Tools preferences can affect how the IDE interacts with Gradle.
Common pitfalls and their avoidance
- Make sure no version-specific configurations or scripts in your
build.gradle
are hijacking the JVM setup. - If you're a heavy user of features like incremental compilation, check your toolchain configurations as they might have hidden JDK dependencies.
Was this article helpful?