Sonar coverage across multi modules project

Informations

Sonar version : ‘org.sonarqube’ version ‘4.4.1.3373’
Gradle version : 8.5
Java : 21

The sonar server is deployed on the cloud.

Project structure

with ./gradlew -q projects

Root project ‘rootProject’
±-- Project ‘:app’
±-- Project ‘:module1’
±-- Project ‘:module2’
±-- Project ‘:module3’
-– Project ‘:module4’


app build.gradle

dependencies {
implementation project(‘:module1’)
implementation project(‘:module2’)
implementation project(‘:module3’)
implementation project(‘:module4’)
}


I have a buildSrc file with :

plugins {
    id 'java'
    id 'jacoco'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    maven {
// blablabla
        }
    }
}

dependencies {
// common dependencies
}

sourceSets {
    test {
        java {
            srcDir file('src/test/java')
        }
        resources {
            srcDir file('src/test/java')
            srcDir file('src/test/resources')
            exclude '**/*.java'
        }
    }
}

jacocoTestReport {
    dependsOn 'compileJava', 'processResources'
    reports {
        xml.required = true
    }
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            // blablabla
        }))
    }
}
test.finalizedBy jacocoTestReport

tasks.named('test') {
    useJUnitPlatform()
}

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs << "-parameters"
}

What I tried and what I want to achieve

aggegate Jacoco reports with ‘jacoco-report-aggregation’ and use sonar on the xml file generated.
I want a global report which is named as the root project “rootProject” on the sonar server of all subprojects.

buildSrc build.gradle

plugins {
    id 'groovy-gradle-plugin'
    id 'org.sonarqube' version '4.4.1.3373'
    id 'jacoco-report-aggregation'
}

sonar {
	properties {
		property "sonar.host.url", "${url}"
		property "sonar.projectKey", "${projectKey}"
		property "sonar.login", "${login}"
		property "sonar.sourceEncoding", "UTF-8"
		property 'sonar.language', 'java'
		property 'sonar.coverage.exclusions', // blablabla
		property "sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml"
	}
}

tasks.named('check') {
	dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
}

The problem is no aggregation report is generated with this configuration.
If I move the sonar block to module ‘app’ I have a global report but sonar don’t use it and create result only on ‘app’.

In the documentation they say to apply sonar and jacoco aggregation on the root project so I think it is in buildSrc build.gradle file.
The usage of build.gradle in the root directory is highly discouraged

Hi,

Welcome to the community!

Unfortunately, this is out of scope for us. We only deal with the report once it’s created and fed into analysis.

You probably want to ask the JaCoCo folks about this.

 
HTH,
Ann

1 Like