Problem with configuration of CLI Scanner for inclusion of test sources

We are using SonarQube 8.9 LTS (an update to 9.9 is planned in the future but currently out of reach) and the Sonar Scanner CLI

In our current project, we use the CLI Scanner because we want to analyze both a Typescript/Node frontend and a Java/Gradle backend in the same Sonar project (and so using the Gradle Scanner directly to handle the configuration for us is not an option).

However, I am uncertain in a few cases about how to set up the configuration properties for the CLI scanner correctly:

  • sonar.sources + sonar.tests
    If I want my test code to show up for analysis in SonarQube, do I need include the paths to the test code in sonar.sources and then distinguish them from the main code by adding them to sonar.tests? Or is it sufficient to only add the test code to sonar.tests? (We are currently doing the latter, but I noticed that no tests show up in our SonarQube instance - unlike with other projects that use the Gradle Scanner).
  • +
    Basically a similar question as with the sources above: Should the include only the test libraries (such as JUnit) or is it okay if it also redundantly contains the full classpath that is already included in

Our configuration currently looks like this (trimmed to the properties I believe to be relevant for this issue), but we only see our main sources and no test sources in SonarQube:

# --- shared ---


({{SONAR_JAVA_LIBRARIES}} and {{SONAR_JAVA_TEST_LIBRARIES}} are placeholders that get substituted with the actual resolved Gradle dependencies before executing the Sonar analysis in the CI build.)

Our CI build shows the following log output:

Indexing files...
Project configuration:
  Excluded sources: **/generated/**/*.java, **/*.spec.ts, **/src/assets/docs/**/*.html, ./my-project-client/**/*.spec.ts, ./my-project-server/**/*
  Included tests: ./my-project-client/**/*.spec.ts, ./my-project-server/**/*

The exclusion of **/generated/**/*.java is from our global SonarQuble exclusion, but I don’t see why ./my-project-server/**/* would show up in the excluded sources based on my configuration above.

Nevermind, I figured out the issue myself. The problem seems to have been that I tried to qualify sonar.test.inclusions with relative paths just like the sonar.tests property. But instead of leading with ./, I needed to lead with **/ for these to work. I noticed my mistake when I tried qualifying sonar.exclusions with ./ as well and the exclusions stopped working.

1 Like

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