-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
164 lines (148 loc) · 6.28 KB
/
Copy pathbuild.gradle
File metadata and controls
164 lines (148 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
plugins {
id 'java'
id 'org.springframework.boot' version '3.5.15'
id 'io.spring.dependency-management' version '1.1.7'
// Jacoco 플러그인 추가
id 'jacoco'
}
group = 'com.team6.moduply'
version = '0.0.1-SNAPSHOT'
description = 'sb10-moduply-team6'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
// jacoco 버전
jacoco {
toolVersion = "0.8.11"
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testCompileOnly 'org.projectlombok:lombok'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testAnnotationProcessor 'org.projectlombok:lombok'
// Testcontainers
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:postgresql'
// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.15'
}
// =========================================
// 테스트 태스크 설정
// A.dependsOn(B): A를 실행하려면 B가 먼저 실행되어야 함
// A.finalizedBy(B): A가 실행되고 난 뒤 B가 반드시 실행됨 (A가 실패해도 B는 실행됨)
// =========================================
tasks.named('test') {
useJUnitPlatform {
// 1. 제외할 태그 처리 (-PexcludeTags=integration)
if (project.hasProperty('excludeTags')) {
excludeTags project.property('excludeTags').toString()
.split(',')
.collect { it.trim() }
.findAll { !it.isEmpty() }
}
// 2. 포함할 태그 처리 (-PincludeTags=repository)
if (project.hasProperty('includeTags')) {
includeTags project.property('includeTags').toString()
.split(',')
.collect { it.trim() }
.findAll { !it.isEmpty() }
}
}
systemProperty 'spring.profiles.active', 'test'
finalizedBy jacocoTestReport // test 태스크가 끝난 직후 jacocoTestReport 태스크를 자동으로 실행
}
// =========================================
// 커버리지 집계에서 제외할 클래스 목록
// 리포트와 검증 태스크 양쪽에서 공통으로 사용
// =========================================
def excludes = [
'**/entity/**',
'**/dto/**',
'**/mapper/**',
'**/enums/**',
'**/config/**',
'**/exception/**',
'**/batch/**',
'**/*Application.java',
'**/Q*.class'
]
// =========================================
// 커버리지 최소 기준값
// 이 변수가 jacocoTestCoverageVerification 보다 "위쪽"에 있어야
// 아래에서 정상적으로 참조됨 (Gradle은 선언 순서를 따라 읽음)
// dev 기준: 0.40 / main 기준: 0.80 (CI에서 -PcoverageMinimum으로 주입)
// =========================================
def coverageMinimum = project.hasProperty('coverageMinimum')
? (project.property('coverageMinimum') as String).toBigDecimal()
: 0.03
// =========================================
// JaCoCo 커버리지 리포트 생성 태스크 설정
// =========================================
jacocoTestReport {
// jacocoTestReport 실행 전 test 태스크가 먼저 실행되도록 보장
dependsOn test
reports {
xml.required = true // XML 리포트 생성 활성화 (CI / Codecov 업로드용)
html.required = true // HTML 리포트 생성 활성화 (개발자용 — build/reports/jacoco/test/html)
}
// 제외 규칙을 실제 커버리지 측정 대상 클래스 디렉터리에 적용
// https://www.baeldung.com/jacoco-report-exclude
classDirectories.setFrom(
// 기존 클래스 디렉터리 목록을 순회하며
// files() : Groovy 리스트 -> Gradle FileCollection 으로 타입 변환
// classDirectories.files : build/classes/java/main
files(classDirectories.files.collect {
// it = build/classes/java/main 디렉터리 각각
fileTree(dir: it, exclude: excludes)
// excludes에 매칭되는 파일을 제외한 파일 트리로 재구성
})
)
finalizedBy 'jacocoTestCoverageVerification' // 리포트 생성 후 커버리지 검증 태스크를 자동 실행
}
// =========================================
// 테스트 커버리지 검증 태스크
// 여기서 정한 minimum 미달 시 이 태스크가 실패 → build 실패로 이어짐
// =========================================
jacocoTestCoverageVerification {
dependsOn jacocoTestReport // 검증 전에 리포트가 먼저 생성되도록 보장
violationRules {
rule {
element = 'BUNDLE' // 검증 단위 - 프로젝트 전체 (기본값)
limit {
counter = 'LINE' // 측정 기준: 라인 커버리지 (INSTRUCTION - 기본값)
value = 'COVEREDRATIO' // 비교할 값의 종류: 커버된 비율 (0.0 ~ 1.0) (기본값)
minimum = coverageMinimum
// 개발 초반(dev 머지)은 낮게, 최종 완성 단계(main 머지)는 80%로
}
}
}
// 리포트와 동일한 제외 규칙 적용
classDirectories.setFrom(
files(classDirectories.files.collect {
fileTree(dir: it, exclude: excludes)
})
)
}
// =========================================
// build 태스크에 커버리지 검증 연결
// './gradlew build' 실행 시에도 커버리지 검증이 강제되도록 설정
// CI 파이프라인에서 build 명령어만으로도 커버리지 기준 검증 가능
// 기준 미달 시 빌드 자체가 실패하므로 PR Merge가 차단됨
// =========================================
build {
dependsOn 'jacocoTestCoverageVerification'
}