Sonar scanner - Java Runtime error, class version mismatch

Hi all,

I’m trying to run sonar-scanner in AWS CodeBuild for a CodeCommit repository mainly containing Python code.
I’m having issues with the version of the Java Runtime.
Here is the last command that I tried:

sonar-scanner -Dsonar.organization=$Organization -Dsonar.projectKey=$Project -Dsonar.sources=.$HOST -Dsonar.login=$LOGIN

And here is the error:

INFO: Scanner configuration file: /codebuild/output/src025386270/src/sonar-scanner-
967	INFO: Project root configuration file: NONE
968	INFO: SonarQube Scanner
969	INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
970	INFO: Linux 4.14.281-212.502.amzn2.x86_64 amd64
971	INFO: User cache: /root/.sonar/cache
972	INFO: SonarQube server
973	INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
974	INFO: ------------------------------------------------------------------------
976	INFO: ------------------------------------------------------------------------
977	INFO: Total time: 1.739s
978	INFO: Final Memory: 5M/164M
979	INFO: ------------------------------------------------------------------------
980	ERROR: Error during SonarQube Scanner execution
981	ERROR: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
982	ERROR: 

It looks like it’s using Java 8 instead of Java 11, even though I specified in the command to use Java 11. Also, JAVA_HOME and PATH looks correctly pointing to the right paths:


echo $PATH

Both version of Java are installed in the machine:

ls /usr/lib/jvm
926	java-1.8.0-amazon-corretto
927	java-11-amazon-corretto

Do you have any idea how to fix it?
Thanks a lot!

Hi, isn’t doing what you think it is. From the docs:

…set the property manually (see below). By doing this you’ll specify which JDK classes the analyzer must refer to during the analysis

It tells the analyzer which version of Java the project was compiled with, not which version of Java the analyzer should have started itself with (you see the bootstrap problem there?).

You might try running java -version. I suspect it will point to the Java 8 install.


1 Like


Thank you for your answer!
Ok, I did not know that about the property, it is not useful then.

However, java -version returns:

900  java -version
901	openjdk version "11.0.15" 2022-04-19 LTS
902	OpenJDK Runtime Environment Corretto- (build 11.0.15+9-LTS)
903	OpenJDK 64-Bit Server VM Corretto- (build 11.0.15+9-LTS, mixed mode)

Do you have any idea why it picks another version after?


Okay, I’ve just reviewed my own sonar-scanner installation & I’m reminded that it ships with a JRE. So then I went back to your OP & saw this:

That’s a pretty old version. The current version is 4.7. Can you upgrade and try again?



Hi, thanks again for checking.
You are totally right. After updating it to the latest version it works as expected.

Thanks a lot!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.