diff --git a/build.gradle.kts b/build.gradle.kts index b27d690..c0b2afb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,6 +8,7 @@ plugins { kotlin("plugin.spring") version "1.9.20" kotlin("plugin.jpa") version "1.9.20" kotlin("kapt") version "1.6.21" + jacoco } java.sourceCompatibility = JavaVersion.VERSION_17 @@ -35,6 +36,7 @@ subprojects { apply(plugin = "io.spring.dependency-management") apply(plugin = "kotlin-kapt") apply(plugin = "application") + apply(plugin = "jacoco") dependencies { implementation("org.springframework.boot:spring-boot-starter-web") @@ -49,15 +51,101 @@ subprojects { testRuntimeOnly("com.h2database:h2") } - tasks.withType { + jacoco { + toolVersion = "0.8.11" + } + + tasks.jacocoTestReport { + dependsOn(tasks.test) + reports { + html.required = true + html.outputLocation = layout.buildDirectory.dir("reports/test-coverage.html").get().asFile + csv.required = false + xml.required = false + } + + val excludes = listOf( + "com/whatever/raisedragon/config", + "com/whatever/raisedragon/common", + "com/whatever/raisedragon/infra", + "com/whatever/raisedragon/common/config", + "com/whatever/raisedragon/aws", + "com/whatever/raisedragon/applicationservice/*/dto" + ) + + classDirectories.setFrom( + sourceSets.main.get().output.asFileTree.matching { + exclude(excludes) + } + ) + + finalizedBy(tasks.jacocoTestCoverageVerification) + } + + tasks.jacocoTestCoverageVerification { + val qDomains = mutableListOf() + + for (qPattern in 'A'..'Z') { + qDomains.add("*.Q${qPattern}*") + } + + violationRules { + rule { + enabled = true + element = "CLASS" + + limit { + counter = "BRANCH" + value = "COVEREDRATIO" + // TODO Fix minimum ratio after increasing test coverage ratio + minimum = "0.00".toBigDecimal() + } + + limit { + counter = "LINE" + value = "TOTALCOUNT" + maximum = "200".toBigDecimal() + // TODO Fix minimum ratio after increasing test coverage ratio + minimum = "0.00".toBigDecimal() + } + + excludes = qDomains + } + } + + val excludes = listOf( + "com/whatever/raisedragon/config", + "com/whatever/raisedragon/common", + "com/whatever/raisedragon/infra", + "com/whatever/raisedragon/common/config", + "com/whatever/raisedragon/aws", + "com/whatever/raisedragon/applicationservice/*/dto" + ) + + classDirectories.setFrom( + sourceSets.main.get().output.asFileTree.matching { + exclude(excludes) + } + ) + } + + tasks.test { + useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) + } + + tasks.compileKotlin { kotlinOptions { freeCompilerArgs = listOf("-Xjsr305=strict") jvmTarget = "17" } } - tasks.withType { - useJUnitPlatform() + tasks.compileTestKotlin { + kotlinOptions { + freeCompilerArgs = listOf("-Xjsr305=strict") + jvmTarget = "17" + } } tasks.bootJar {