Hi there,
I am using SonarQube and trying to analyze my project coverage by using JaCoCo.
my project is written in Kotlin and uses Gradle DSL.
somehow, I can’t see any coverage on SonarQube.
when I’m building my project via Jenkins I can notice the following line-
INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
‘sonar.coverage.jacoco.xmlReportPaths’
is already defined inside the build.gradle file and I can see that the XML report generated under build/jacoco/test/jacocoTestReport.xml
build.gradle configuration-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.7.8"
id("io.spring.dependency-management") version "1.1.0"
kotlin("jvm") version "1.7.20"
kotlin("plugin.spring") version "1.7.20"
kotlin("plugin.lombok") version "1.7.21"
id ("jacoco")
id ("org.sonarqube") version "4.0.0.2929"
}
group = "com.myproject"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
repositories {
mavenCentral()
maven { url = uri("https://repo.spring.io/milestone") }
maven { url = uri("https://plugins.gradle.org/m2/") }
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.21")
implementation("org.springframework.boot:spring-boot-starter-web:3.0.3") { exclude(module = "spring-boot-starter-tomcat") }
implementation("org.springframework.boot:spring-boot-starter-cache:3.0.2") // for caching use
implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.7.8") // for caching use
implementation("com.google.guava:guava:31.1-jre") // for caching use 2
implementation("org.springframework.boot:spring-boot-starter-jetty:2.7.8") // instead of tomcat
implementation("org.springframework.boot:spring-boot-starter-actuator:2.7.8") //health & other metrics
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions:1.1.9") // reactive
implementation("org.junit.jupiter:junit-jupiter:5.9.0")
implementation("io.github.microutils:kotlin-logging-jvm:3.0.3") // kotlin logger
implementation(platform("org.apache.logging.log4j:log4j-bom:2.19.0"))
implementation("com.sksamuel.hoplite:hoplite-yaml:2.6.5") // yml to kotlin mapper
implementation("mysql:mysql-connector-java:8.0.32")
implementation("com.zaxxer:HikariCP:3.0.0") // db connection pool
implementation("org.springdoc:springdoc-openapi-data-rest:1.6.14")
implementation("org.springdoc:springdoc-openapi-ui:1.6.14")
implementation("org.springdoc:springdoc-openapi-kotlin:1.6.14")
implementation("org.slf4j:slf4j-api:1.7.29")
implementation("ch.qos.logback:logback-classic:1.2.9")
implementation("ch.qos.logback.contrib:logback-json-classic:0.1.5")
implementation("ch.qos.logback.contrib:logback-jackson:0.1.5")
implementation("com.github.danielwegener:logback-kafka-appender:0.1.0")
implementation("net.logstash.logback:logstash-logback-encoder:7.2")
implementation("jakarta.json:jakarta.json-api:2.1.1")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2")
implementation("org.jetbrains.kotlin:kotlin-test:1.1.51")
implementation("org.gradle.api.plugins:gradle-nexus-plugin:0.3")
implementation("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:4.0.0.2929")
compileOnly("org.projectlombok:lombok:1.18.24")
developmentOnly("org.springframework.boot:spring-boot-devtools")
annotationProcessor("org.projectlombok:lombok:1.18.24")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:2.7.8")
testImplementation(platform("org.testcontainers:testcontainers-bom:1.17.6"))
testImplementation("org.testcontainers:junit-jupiter:1.17.6")
testImplementation("org.springframework.boot:spring-boot-starter-test:3.0.3")
testImplementation("org.mockito:mockito-core:5.2.0")
testImplementation("org.mockito:mockito-inline:5.2.0")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
testImplementation("org.testcontainers:mysql:1.17.6")
testImplementation("com.google.code.gson:gson:2.10.1")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
val sonarLogin: String = System.getenv("sonar_login")
sonarqube {
properties {
property("sonar.projectKey", "model-center")
property("sonar.language", "kotlin")
property("sonar.sources", "src/main/kotlin")
property("sonar.tests", "src/test/kotlin")
property("sonar.sourceEncoding", "UTF-8")
property("sonar.host.url", "https://sq.hq.companyname.com/")
property("sonar.login", sonarLogin)
property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/jacoco/test/jacocoTestReport.xml")
property("sonar.scanner.metadataFilePath", "$projectDir/target/sonar/report-task.txt")
property("sonar.working.directory", "$projectDir/target/sonar/")
}
}
apply(plugin = "org.sonarqube")
jacoco {
toolVersion = "0.8.9"
reportsDirectory.set(layout.buildDirectory.dir("$buildDir/jacoco/"))
}
tasks {
"jacocoTestReport"(JacocoReport::class) {
reports {
xml.required.set(true)
html.required.set(true)
html.outputLocation.set(layout.buildDirectory.dir("$buildDir/jacoco/jacocoHtml"))
}
}}
is there a solution for this case?
Thanks in advance