@@ -3,8 +3,12 @@ plugins {
33 id ' org.springframework.boot' version ' 3.3.5'
44 id ' io.spring.dependency-management' version ' 1.1.6'
55 id " org.sonarqube" version " 5.1.0.4882"
6+ id " jacoco"
67}
78
9+
10+
11+
812group = ' com'
913version = ' 0.0.1-SNAPSHOT'
1014
@@ -24,12 +28,72 @@ repositories {
2428 mavenCentral()
2529}
2630
31+ jacoco {
32+ toolVersion = " 0.8.12"
33+ }
34+
35+ // QueryDSL 제외 패턴
36+ def QDomains = []
37+ for (qPattern in ' *.QA' .. ' *.QZ' ) { // qPattern = '*.QA', '*.QB', ... '*.QZ'
38+ QDomains . add(qPattern + ' *' )
39+ }
40+
41+ def jacocoExcludePatterns = [
42+ // 측정 안하고 싶은 패턴
43+ " **/*Application*" ,
44+ " **/*Config*" ,
45+ " **/*Exception*" ,
46+ " **/*Request*" ,
47+ " **/*Response*" ,
48+ " **/*Dto*" ,
49+ " **/*Interceptor*" ,
50+ " **/*Filter*" ,
51+ " **/*Resolver*" ,
52+ " **/test/**" ,
53+ " **/resources/**"
54+ ]
55+
56+ jacocoTestCoverageVerification {
57+
58+ violationRules {
59+ rule {
60+ // rule 활성화
61+ enabled = true
62+
63+ // 클래스 단위로 룰 체크
64+ element = ' CLASS'
65+
66+ // 라인 커버리지를 최소 80% 만족
67+ limit {
68+ counter = ' LINE'
69+ value = ' COVEREDRATIO'
70+ minimum = 0.60
71+ }
72+
73+ // 브랜치 커버리지를 최소 80% 만족
74+ limit {
75+ counter = ' BRANCH'
76+ value = ' COVEREDRATIO'
77+ minimum = 0.60
78+ }
79+
80+ excludes = jacocoExcludePatterns
81+ }
82+ }
83+ }
84+
2785
2886sonar {
2987 properties {
3088 property " sonar.projectKey" , " prgrms-web-devcourse-final-project_WEB1_1_Bongdari_BE"
3189 property " sonar.organization" , " prgrms-web-devcourse-final-project"
3290 property " sonar.host.url" , " https://sonarcloud.io"
91+ property ' sonar.sources' , ' src'
92+ property ' sonar.language' , ' java'
93+ property ' sonar.test.exclusions' , jacocoExcludePatterns. join(' ,' )
94+ property ' sonar.test.inclusions' , ' **/*Test.java'
95+ property ' sonar.java.coveragePlugin' , ' jacoco'
96+ property ' sonar.coverage.jacoco.xmlReportPaths' , jacocoDir. get(). file(" jacoco/index.xml" ). asFile
3397 }
3498}
3599
@@ -64,4 +128,29 @@ dependencies {
64128
65129tasks. named(' test' ) {
66130 useJUnitPlatform()
131+ finalizedBy ' jacocoTestReport'
132+ }
133+
134+ def jacocoDir = layout. buildDirectory. dir(" reports/" )
135+
136+ jacocoTestReport {
137+ dependsOn test // 테스트가 수행되어야만 report를 생성할 수 있도록 설정
138+ reports {
139+ html. required. set(true )
140+ xml. required. set(true )
141+ csv. required. set(true )
142+ html. destination jacocoDir. get(). file(" jacoco/index.html" ). asFile
143+ xml. destination jacocoDir. get(). file(" jacoco/index.xml" ). asFile
144+ csv. destination jacocoDir. get(). file(" jacoco/index.csv" ). asFile
145+ }
146+
147+ afterEvaluate {
148+ classDirectories. setFrom(
149+ files(classDirectories. files. collect {
150+ fileTree(dir : it, excludes : jacocoExcludePatterns + QDomains ) // Querydsl 관련 제거
151+ })
152+ )
153+ }
154+ finalizedBy jacocoTestCoverageVerification
155+
67156}
0 commit comments