SonarQube unable to analyze project developed using older version of Java

SonarQube unable to analyze projects built using lower version of Java. We are facing issue given below.

Sonar Configurations :
SonarQube Scanner 4.2.0.1873
Java 1.8.0_272 Red Hat, Inc. (64-bit)
SonarQube server 8.5.1

Source code file using java 1.6
added argument for java version mismatch : -Dsonar.java.source=1.6

ERROR :
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:808)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142

Hi,

Welcome to the community!

You can compile to whatever version you like, but you need to analyze with at least Java 8.

 
HTH,
Ann

Hi

Thank you for your quick response.

As mentioned in my query, we are using Java 1.8.0_272 in our environment where sonar scanner is running.

Can you please suggest on this further?

Thanks
Swarnab

Hi Swarnab,

Is $JAVA_HOME set in your environment? And if so, does it point to a lower version than Java 8? When the scanner CLI finds JAVA_HOME it uses that instead of the embedded JVM.

 
Ann

Hi G Ann Campbell,

I am having the same issue and my JAVA_HOME is set to Java 8. I do have another java variable JAVA_HOME_7_X64 that is set to 7. Does it explicitly look for JAVA_HOME?

Thanks,
Ryan

Hi Ryan,

How are you analyzing? Maven? Gradle? Something else?

 
Ann

Hello,

I was using the CLI because unfortunately this project uses Ant to build. I figured out that it was looking for JAVA_HOME__X64 by running the pipeline in debug mode.

1 Like