Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsupported major.minor version Exception for sonar-scanner

I am trying to analyze my source code using SonarQube. I am trying to use sonar-scanner as my tool to run analysis from command line. I followed the guidelines presented in this documentation article: http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

When I try to test the installation by running sonar-scanner -h I am getting the following error:

➜  ~ sonar-scanner -h
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

From the error it looks like its not finding the right version for JAVA/JRE to run the cli tool. My understanding was that the tool should work with any Java 1.7+ version. I am using Oracle JDK 1.7.0_55. I also tried using OpenJDK 1.8 but I am still getting the same error. I also checked my JAVA_HOME variable is set to the right JDK directory.

Any help in the right direction is appreciated.

like image 415
Amrish Avatar asked Sep 24 '16 14:09

Amrish


People also ask

How to fix unsupportedclassversionerror - unsupported major?

As you know now that root cause of any java.lang.UnsupportedClassVersionError: Unsupported major.the minor version is incompatible JRE version at run-time, but changing JRE is not the only solution you have, you can even compile your class file for lower JRE version. In order to adapt this solution, you need to re-compile your project.

How to fix unsupported major version 52?

As I said earlier, there are two ways to fix "Unsupported major.minor version 52.0" error, first upgrade to higher Java version or compiler Java source files for lower Java version of target environment.

What is the default system encoding for sonar?

Default is default system encoding #sonar.sourceEncoding=UTF-8 Expand the downloaded file into the directory of your choice. We'll refer to it as $install_directory in the next steps.

What if a sonar project cannot be created in the root directory?

If a sonar-project.properties file cannot be created in the root directory of the project, there are several alternatives: The properties can be specified directly through the command line.


2 Answers

this have been already answered at length here : Unsupported major.minor version 52.0 and here : How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

the rationale is that you're trying to execute Sonar on a Java 7 or lower when the sonar classes have been compiled for java 8 thus triggering this error.

like image 200
Alex Avatar answered Oct 29 '22 00:10

Alex


After Struggling with this for a while, I found the cause of the problem. The CLI is looking at your JAVA_HOME path variable to figure out the version of Java it needs to use. even tough the default java and javac commands were pointing to JDK 8, setting the JAVA_HOME environment variable to your JDK 8 root directory solved the issue.

Hope this helps other folks facing similar issue.

like image 33
Amrish Avatar answered Oct 29 '22 01:10

Amrish