Fatal error compiling: invalid target release: 1.8 ->
Fix the Java 1.8 compile error ASAP by configuring your JDK to version 1.8. In Maven, use this:
For special Gradle fans, update your build.gradle
like this:
Make sure JAVA_HOME
has the correct direction to JDK 1.8, and run your build with the finest JDK.
Making Environment Variables Your Friends
Getting JAVA_HOME and Maven's POM file to play ball is crucial to the build process. If they don't, you're in for a rough innings with Maven.
To shine the light on your path to victory (read: set environment variables):
- Windows:
- Like your favorite shopping routine: Right-click -> Properties -> Advanced System Settings -> Fill cart (Environment Variables)
- Rewrite JAVA_HOME to guide it to your JDK 1.8 lair
- Unix-like systems (Linux, macOS):
- Get
~/.bashrc
or~/.zshrc
to confess (export JAVA_HOME=<path-to-jdk-1.8>
)
- Get
Maven and Java: A Love Story
A mismatch between Maven and the JDK version is a recipe for a disaster--well, fatal error at least. Make sure the maven-compiler-plugin is dating the right JDK version.
This is what your maven-compiler-plugin should be whispering:
Plan B: When JDK 1.8 is the One That Got Away
If you and JDK 1.8 are not meant to be, simply adjust the target release in your Maven POM or Gradle build script to comfort your JDK version.
Say No to JDK-JRE Contradictions
Eclipse IDE users, listen up! If the "invalid target release" looms over you, here's the path: Window -> Preferences -> Java -> Installed JREs. Make sure it's JDK 1.8 calling the shots, not just the JRE.
When Version Mismatch Throws Tantrums
If java -version
and javac -version
are like siblings not getting along, it's likely your PATH is serving different cuisines. Update it to include the JDK 1.8 bin directory.
Can't make peace between the versions?
- Temporarily expel the rebel versions using
unset
command. - Permanently exile conflicting PATH entries by editing config files (
~/.bashrc
or~/.zshrc
)
SDKMAN! to the Rescue
Referee your SDK versions with SDKMAN!. It's super handy to switch Java SDK versions sans manual tweaks.
Use these spells to install JDK 1.8 and switch:
Was this article helpful?