diff --git a/build.gradle b/build.gradle index 24f00c97d..bc529f8d8 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.5.0' id 'io.spring.dependency-management' version '1.1.7' + id 'jacoco' } group = 'konkuk.thip' @@ -96,3 +97,5 @@ clean.doLast { tasks.named('test') { useJUnitPlatform() } + +apply from: "$rootDir/jacoco.gradle" \ No newline at end of file diff --git a/jacoco.gradle b/jacoco.gradle new file mode 100644 index 000000000..e7e16a6f8 --- /dev/null +++ b/jacoco.gradle @@ -0,0 +1,79 @@ +jacoco { + toolVersion = "0.8.12" +} + +tasks.named('test') { + useJUnitPlatform() + finalizedBy tasks.jacocoTestReport +} + +tasks.named('jacocoTestReport', JacocoReport) { + dependsOn(tasks.test) + + def mainClasses = files(sourceSets.main.output).asFileTree.matching { + exclude( + "**/generated/**", + "**/build/**", + "**/*Application*", + "**/*Config*", + "**/*Dto*", + "**/*Request*", + "**/*Response*", + "**/generated/querydsl/**", + "**/Q*.*" + ) + } + + additionalSourceDirs.from files(sourceSets.main.allSource.srcDirs) + sourceDirectories.from files(sourceSets.main.allSource.srcDirs) + classDirectories.setFrom(mainClasses) + executionData.from fileTree(project.rootDir) { + include "**/build/jacoco/*.exec" + } + + reports { + html.required.set(true) + xml.required.set(true) + csv.required.set(false) + } +} + +tasks.named('jacocoTestCoverageVerification', JacocoCoverageVerification) { + dependsOn(tasks.test) + + classDirectories.setFrom( + files(sourceSets.main.output).asFileTree.matching { + exclude( + "**/generated/**", + "**/build/**", + "**/*Application*", + "**/*Config*", + "**/*Dto*", + "**/*Request*", + "**/*Response*", + "**/generated/querydsl/**", + "**/Q*.*" + ) + } + ) + + violationRules { + rule { + element = 'CLASS' + limit { + counter = 'INSTRUCTION' + value = 'COVEREDRATIO' + minimum = 0.00 + } + limit { + counter = 'BRANCH' + value = 'COVEREDRATIO' + minimum = 0.00 + } + } + } +} + +tasks.named('check') { + dependsOn tasks.named('jacocoTestCoverageVerification') +} \ No newline at end of file