11

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.

Amrish
  • 679
  • 1
  • 8
  • 20

2 Answers2

17

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.

Amrish
  • 679
  • 1
  • 8
  • 20
4

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.

Community
  • 1
  • 1
Alex
  • 189
  • 1
  • 7
  • As I have already stated in my question I have tried running the tool with both JDK 7 and JDK 8. I am still getting the same error. – Amrish Sep 25 '16 at 02:15
  • as you said yourself in the question, "you have checked the JAVA_HOME environment variable" .... i'm sorry but aside from that i pointed you on the correct answer, your version of java executed was wrong... – Alex Sep 25 '16 at 09:47