Showing only coverage percentage not showing number of unit test cases

Build.gradle file

plugins {
	id 'org.springframework.boot' version '2.7.1'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
	id 'jacoco'
	id 'org.sonarqube' version '3.3'

group = 'com.sonar'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation group: 'junit', name: 'junit', version: '4.13.2'


tasks.named('test') {

sonarqube {
	properties {

jacocoTestReport {
	reports {
		xml.enabled true
test.finalizedBy jacocoTestReport
tasks.named('sonarqube').configure {
	dependsOn test

sonar properties that I am using

I am running sonarqube command everything working as expected but number of unit test cases not showing and when I am changing property of sonar.sources to this
then both coverage and number of unit test cases showing but getting error in build
java can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
I have used exlusions also but no luck .
Thanks in advance.

Hey there.

If you’re using the SonarScanner for Gradle (and executing gradle sonarqube to run the scan), you really shouldn’ have to define anything like this:

It should automatically be picked up from the context of the build.

What led you to setting these properties in the first place?

If I didn’t specify property in sonar properties I am getting exception while creating build.

INFO: ------------------------------------------------------------------------
INFO: Total time: 3.204s
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
ERROR: SonarQube scanner exited with non-zero code: 2
Finished: FAILURE