Scan source directory of any project

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

Hi,
I am using sonarQube 9.0.1 community addition.

I want to scan multiple project’s source directory of different language.

I tried to use sonarscanner for java project but it gives below error.

ERROR: Error during SonarScanner execution
org.sonar.java.AnalysisException: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.

Can’t I scan java source files with sonar scanner.
As I want common method for all project scan.

Thanks in advance.

Hi.

Technically it’s possible but it’s not too easy. Look at the documentation:

Java Analysis and Bytecode

Compiled .class files are required for java projects with more than one java file. If not provided properly, analysis will fail with the message:

Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.

(…)

If you are not using Maven or Gradle for analysis, you must manually provide bytecode to the analysis. You can also analyze test code, and for that you need to provide tests binaries and test libraries properties.

If your project can be build with Maven/Gradle, using the SonarScanner for Maven/Gradle is soooo much easier than setting all properties manually, there’s no practical reason to use the plain SonarScanner.

Hi Avani

Seem that you need to build your project prior to run the analysis.
Try a mvn install or gradle build before.

HTH

Thanks Mathieu and Felipe.

Hi Team,
I got below things from link “Overview | SonarQube Docs
" Will all files be analyzed?

By default, only files that are recognized by your edition of SonarQube are loaded into the project during analysis. For example if you’re using SonarQube Community Edition, which includes analysis of Java and JavaScript, but not C++, all .java and .js files would be loaded, but .cpp files would be ignored."

Is this means Java file here or class file?

If java file then can you please provide me a link or doc which can show me steps for analysing java source code.

Thanks