Today when I run gradle test, I hit Unsupported major.minor version 52.0 error. It comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.

The Ubuntu archives have multiple versions of OpenJDK available. One of these is designated as the default and this has the package names default-jdk and default-jre. The java and javac programs will be symlinked to the binaries from this default JDK. On my Ubuntu, the default packages were linked to the openjdk-7-jdk and openjdk-7-jre packages.

However, you might want to install and use other versions of JDK. For example, to use Java 8 I did:

sudo apt install openjdk-8-jdk

The problem is that java, javac and other binaries still point to the default Java version. To switch the default Java binaries, use the update-java-alternatives tool.

To list the Java versions installed on your system, use the –list option:

update-java-alternatives --list
java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64

To set one of the above Java versions as the default, use the –set option:

$ sudo update-java-alternatives --set java-1.8.0-openjdk-amd64