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.
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With