Gradle build in Eclipse Unsupported major.minor version 52.0

Get this error when building with Gradle in Eclipse Luna

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> org/hibernate/build/gradle/animalsniffer/AnimalSnifferExtension : Unsupported major.minor version 52.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Total time: 21.351 secs

The JRE is C:\Program Files (x86)\Java\jdk1.7.0_17

First we need to know what this message means, the major version here means the JDK version, here is a list shows the major version number for each generation JDK:

Java SE 8 = 52
Java SE 7 = 51
Java SE 6.0 = 50
Java SE 5.0 = 49
JDK 1.4 = 48
JDK 1.3 = 47
JDK 1.2 = 46
JDK 1.1 = 45

This message is telling us there are something compiled with JDK 8, but run with JDK lower than 8, in this case, the running JDK is the JDK 1.7 used by Eclipse. When building the Gradle project, it run the class AnimalSnifferExtension which may be compiled by JDK 8.

The solution is install JDK 8. After installation, go to cmd window and go to Eclipse Luna home directory and execute eclipse.exe.

Then in Eclipse open Preferences - Installed JRE and add the new JDK 8 and activate it.

activate jdk 8 in eclipse Unsupported major.minor version 52.0

The problem should gone.

Another problem you may need to care is JDK 8 using a different way to set java.exe environment, you may find you can not switch back to JDK 7 easily.

Here is a solution to keep different versions of JDK on same system and make it easier to switch between different versions of JDK JDK 8 and C:\ProgramData\Oracle\Java\javapath.