More informative error logging when java class files are missing

I have a use case for running a large scale analysis on an extensive Maven multi-module project.

It has over 2000+ modules and counting. However, when running the top-down compilation and running the sonar:sonar goal, occasionally one of the developers has introduced some code that isn’t guaranteed to have .class files after the compile phase.

In this situation i get an error message like this:

[2020-07-22T02:40:38.370Z] [INFO] [jenkins-event-spy] Generated /jenkins/workspace/_Static_Code_Analysis_v3.1.build@tmp/withMaven1439654e/maven-spy-20200722-031543-392008160896301520380.log
[2020-07-22T02:40:38.370Z] [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project murex: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property. -> [Help 1]
[2020-07-22T02:40:38.370Z] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project murex: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.

Between runs of sonar over 200+ commits could have occured on this very large project, and with the error message above it is very unclear where the missing .class files are originating from.

Is there anything that can be done to enrich the error logging in this context?

I would expect something to say :

[2020-07-22T02:40:38.310Z] [INFO] Reactor Summary:
[2020-07-22T02:40:38.310Z] [INFO] 
[2020-07-22T02:40:38.370Z] [INFO] ------------------------------------------------------------------------
[2020-07-22T02:40:38.370Z] [INFO] BUILD FAILURE
[2020-07-22T02:40:38.370Z] [INFO] ------------------------------------------------------------------------
[2020-07-22T02:40:38.370Z] [INFO] Total time:  01:24 h
[2020-07-22T02:40:38.370Z] [INFO] Finished at: 2020-07-22T04:40:38+02:00
[2020-07-22T02:40:38.370Z] [INFO] ------------------------------------------------------------------------
[2020-07-22T02:40:38.370Z] [INFO] [jenkins-event-spy] Generated /jenkins/workspace/_Static_Code_Analysis_v3.1.build@tmp/withMaven1439654e/maven-spy-20200722-031543-392008160896301520380.log
[2020-07-22T02:40:38.370Z] [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project murex: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property. -> [Help 1]
[2020-07-22T02:40:38.370Z] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project murex: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.
**The module which did not declare its .class files is :sub-project-name:group:artifact , the list of java files with no classes has been dumped to sonarMissingResources.log** 
[2020-07-22T02:40:38.372Z] [ERROR] After correcting the problems, you can resume the build with the command
[2020-07-22T02:40:38.372Z] [ERROR]   mvn <args> -rf :top-level-project-name

Is this a valid concern, or are there simpler ways to resolve this concern ?

Hello @Necrontyr,

To my knowledge, the behavior is the following:
Note that this is only true for SonarScanner, others scanner are filling properties for you.

  • If a project contains .java files, and the property sonar.java.binaries is not set, the analysis will fail.
  • Then, if the property is set, but a .class is missing, you may end up with less precise results, but the analysis should not fail, and no warning will be shown.

The last point is not ideal, we will discuss how to improve this situation at one point.

What I expect is happening here is that a commit adds a .java file in a project, making the analysis fail. You should make sure the property sonar.java.binaries is set for every project.