Currently I have updated my application to springboot 3 and Java 21, unfortunately the configuration classes are not ignored anymore which affects the coverage percentage.
Build gradle:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
jacoco
id("org.openapi.generator") version "7.4.0"
id("org.springframework.boot") version "3.2.4"
id("io.spring.dependency-management") version "1.1.0"
id("org.sonarqube") version "3.3"
id("info.solidsoft.pitest") version "1.7.4"
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.23"
kotlin("jvm") version "1.9.23"
kotlin("plugin.spring") version "1.9.23"
kotlin("kapt") version "1.9.23"
kotlin("plugin.serialization") version "1.9.23"
}
pitest {
setProperty("junit5PluginVersion", "0.12")
setProperty("testPlugin", "junit5")
setProperty("targetClasses", listOf("com.bff.*"))
setProperty("outputFormats", listOf("HTML"))
}
sourceSets {
main {
java {
srcDir("build/generated/src/main/java")
}
}
}
openApiGenerate {
generatorName.set("spring")
inputSpec.set("$rootDir/src/main/resources/openapi.yaml")
outputDir.set("$buildDir/generated")
packageName.set("com.bff.controller.openapi")
apiPackage.set("com.bff.controller.openapi.api")
modelPackage.set("com.bff.controller.openapi.model")
skipOverwrite.set(false)
configOptions.set(
mapOf(
Pair("interfaceOnly", "true"),
Pair("skipDefaultInterface", "true"),
Pair("identifierNamingConvention", "snake_case"),
Pair(
"additionalModelTypeAnnotations",
"@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)"
),
Pair("useJakartaEe", "true"),
Pair("useSpringBoot3", "true")
)
)
}
group = "com.bff"
version = "1.1.0"
java.sourceCompatibility = JavaVersion.VERSION_21
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
extra["log4j2.version"] = "2.15.0"
extra["springCloudVersion"] = "2023.0.1"
dependencies {
IMPLEMENTATIONS...................
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
jacoco {
toolVersion = "0.8.11"
}
tasks.withType<JacocoReport> {
classDirectories.setFrom(
sourceSets.main.get().output.asFileTree.matching {
exclude(
"**/configuration/**",
"**/data/**",
"**/enum/**",
"**/mapper/**",
"**/openapi/**",
"**/exception/**",
"**/factory/**",
"**/context/**",
"**/Application.*"
)
}
)
}
sonarqube {
properties {
property("sonar.java.coveragePlugin", "jacoco")
property("sonar.coverage.jacoco.xmlReportPath", layout.buildDirectory.file("/reports/jacoco/test/jacocoTestReport.xml").get())
property("sonar.inclusions", "**/src/main/kotlin/**/*")
property(
"sonar.coverage.exclusions",
"**/configuration/**," +
"**/data/**," +
"**/enum/**," +
"**/mapper/**," +
"**/openapi/**," +
"**/exception/**," +
"**/factory/**," +
"**/context/**," +
"**/util/**," +
"**/Application.*"
)
}
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
xml.required.set(true)
html.required.set(true)
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "21"
}
}
tasks.getByName<Jar>("jar") {
enabled = false
}
tasks.withType<Test> {
useJUnitPlatform()
finalizedBy(tasks.getByName("jacocoTestReport"))
}
tasks.register<Zip>("zip") {
archiveFileName.set("${project.rootProject.name}-${project.rootProject.version}.zip")
destinationDirectory.set(layout.buildDirectory.dir("${project.buildDir}/distributions"))
from(layout.buildDirectory.dir("${project.buildDir}/libs")) {
exclude("*-plain.jar")
}
}
tasks.compileKotlin {
dependsOn("openApiGenerate")
kotlinOptions.jvmTarget = "21"
}
tasks.compileTestKotlin {
dependsOn("openApiGenerate")
kotlinOptions.jvmTarget = "21"
}
project.tasks.withType(KotlinCompile::class.java).configureEach {
dependsOn("openApiGenerate")
kotlinOptions.jvmTarget = "21"
}
As you can see I added ‘property(“sonar.coverage.exclusions”, “/configuration/,” +…’ but in the report
I tried to put the whole path but it doesn’t work.