Sonar-scanner failing to scan the java code

I am facing the below error while trying to scan the code using sonar-scanner that has java code and I am using sonarqube 9.9 version.
Also is there any special configuration to be added to either sonar-scanner or sonarqube 9.9 to be compatible to scan the repo that has java code.

  • Here’s the error message
    ERROR: Error during SonarScanner execution Your project contains .java files, please provide compiled classes with property, or exclude them from the analysis with sonar.exclusions property.

Hey there.

The analysis of Java requires compiled Java bytecode. For analyzing Java code, we recommend using the relevant scanner based on how your code is built: meaning the SonarScanner for Maven, SonarScanner for Gradle, or SonarScanner for Ant.

I tried scanning the java maven project but the build is failed and the error message is as below.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sonarscanner-maven-basic: Fatal error compiling: invalid flag: --release

This looks more like an issue with the version of Java you’re using than anything to do with SonarQube.

Once you have a working Java build, I suggest adding in the SonarQube analysis.

Yeah I updated the java version and it works for maven now.
Thanks for your guidance

1 Like

I am facing errors as mentioned below for different repositories of maven projects

  1. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M7:test (default-test) on project struts2-jasperreports-plugin:

  2. [ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.8.0:compile (scala-compile-first) on project spark-tags_2.12: Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:4.8.0:compile failed: org.apache.commons.exec.ExecuteException: Process exited with an error: 255 (Exit value: 255)

Can you please guide me about the errors I’m facing. I am not sure if it’s because of issues with the project’s code or with the scanner and to make sure the scanner has configured properly I did all possible ways using the help of documentation from SonarScanner for Maven


Hey there.

These issues don’t look related to sonar – do they persit if you remove the sonarqube plugin/goal?

Yes, without plugin for some projects it’s able to build and scan.
Also I tried removing test cases from java files of test folder and for few it’s working, but we can’t remove the test cases every time is it!
So is there a way to scan the project in a smooth way?