-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
246 lines (212 loc) · 7.29 KB
/
build.gradle.kts
File metadata and controls
246 lines (212 loc) · 7.29 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
id(Plugins.SPRING_BOOT) version Versions.SPRING_BOOT
id(Plugins.SPRING_DEPENDENCY_MANAGEMENT) version Versions.SPRING_DEPENDENCY_MANAGEMENT
kotlin(Plugins.Kotlin.Short.KAPT) version Versions.KOTLIN
kotlin(Plugins.Kotlin.Short.JVM) version Versions.KOTLIN
kotlin(Plugins.Kotlin.Short.SPRING) version Versions.KOTLIN
kotlin(Plugins.Kotlin.Short.JPA) version Versions.KOTLIN
id(Plugins.DETEKT) version Versions.DETEKT
id(Plugins.JACOCO)
id(Plugins.SONAR_QUBE) version Versions.SONAR_QUBE
}
allprojects {
group = "org"
version = "0.0.1-SNAPSHOT"
repositories {
mavenCentral()
}
}
// 테스트하지 않는 코드 패턴 (JaCoCo + SonarQube 커버리지 + CPD 공통)
val testExclusionPatterns = listOf(
"**/*Application*",
"**/config/**",
"**/*Config*",
"**/exception/**",
"**/*Exception*",
"**/*ErrorCode*",
"**/dto/**",
"**/*Request*",
"**/*Response*",
"**/*Entity*",
"**/annotation/**",
"**/generated/**"
)
// SonarQube 전체 분석 제외 패턴 (분석 자체가 의미 없는 파일들)
val sonarGlobalExclusions = listOf(
"**/build/**",
)
subprojects {
apply(plugin = Plugins.SPRING_BOOT)
apply(plugin = Plugins.SPRING_DEPENDENCY_MANAGEMENT)
apply(plugin = Plugins.Kotlin.SPRING)
apply(plugin = Plugins.Kotlin.JPA)
apply(plugin = Plugins.Kotlin.JVM)
apply(plugin = Plugins.JACOCO)
apply(plugin = Plugins.Kotlin.KAPT)
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(Versions.JAVA_VERSION.toInt()))
}
}
configurations.all {
exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging")
}
dependencies {
implementation(Dependencies.Spring.STARTER_LOG4J2)
}
plugins.withId(Plugins.Kotlin.ALLOPEN) {
extensions.configure<org.jetbrains.kotlin.allopen.gradle.AllOpenExtension> {
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.MappedSuperclass")
annotation("jakarta.persistence.Embeddable")
}
}
// Configure Kotlin compiler options
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs += listOf(
"-Xjsr305=strict",
"-Xconsistent-data-class-copy-visibility"
)
jvmTarget = Versions.JAVA_VERSION
javaParameters = true
}
}
}
// QueryDSL 설정
val querydslDir = "${layout.buildDirectory.get()}/generated/querydsl"
sourceSets {
main {
kotlin {
srcDir(querydslDir)
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs>().configureEach {
doFirst {
delete(querydslDir)
}
}
// 루트 프로젝트에서 모든 JaCoCo 설정 관리
configure(subprojects) {
jacoco {
toolVersion = Versions.JACOCO
}
tasks.withType<Test> {
useJUnitPlatform()
finalizedBy("jacocoTestReport")
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = false
}
}
// 각 서브모듈의 JaCoCo 테스트 리포트 설정
tasks.withType<JacocoReport> {
dependsOn("test")
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(true)
}
classDirectories.setFrom(fileTree(layout.buildDirectory.dir("classes/kotlin/main")) {
exclude(testExclusionPatterns)
})
executionData.setFrom(fileTree(layout.buildDirectory) {
include("jacoco/*.exec")
})
}
}
tasks {
withType<Jar> { enabled = true }
withType<BootJar> { enabled = false }
}
// 루트 프로젝트 JaCoCo 통합 리포트 설정
tasks.register<JacocoReport>("jacocoRootReport") {
description = "Generates an aggregate report from all subprojects"
group = "reporting"
dependsOn(subprojects.map { it.tasks.named("test") })
sourceDirectories.setFrom(subprojects.map { it.the<SourceSetContainer>()["main"].allSource.srcDirs })
classDirectories.setFrom(subprojects.map { subproject ->
subproject.fileTree(subproject.layout.buildDirectory.get().asFile.resolve("classes/kotlin/main")) {
exclude(testExclusionPatterns)
}
})
executionData.from(subprojects.map { subproject ->
subproject.fileTree(subproject.layout.buildDirectory.dir("jacoco")) {
include("**/*.exec")
}
})
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(true)
}
}
// SonarQube 설정을 루트에서 모든 서브모듈에 대해 설정
sonar {
properties {
property("sonar.projectKey", "YAPP-Github_26th-App-Team-1-BE")
property("sonar.organization", "yapp-github")
property("sonar.host.url", "https://sonarcloud.io")
property(
"sonar.coverage.jacoco.xmlReportPaths",
"${layout.buildDirectory.get()}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
)
property("sonar.kotlin.coveragePlugin", Plugins.JACOCO)
property("sonar.kotlin.version", Versions.KOTLIN)
property("sonar.exclusions", sonarGlobalExclusions.joinToString(","))
property("sonar.cpd.exclusions", testExclusionPatterns.joinToString(","))
property("sonar.coverage.exclusions", testExclusionPatterns.joinToString(","))
}
}
// SonarQube 태스크가 통합 JaCoCo 리포트에 의존하도록 설정
tasks.named("sonar") {
dependsOn("jacocoRootReport")
onlyIf { System.getenv("SONAR_TOKEN") != null }
}
/**
* CI용 - 전체 품질 검증 파이프라인을 실행합니다. (테스트, 커버리지, SonarQube 분석)
* GitHub Actions에서 이 태스크 하나만 호출합니다.
* 사용 예: ./gradlew fullCheck
*/
tasks.register("fullCheck") {
description = "Runs all tests, generates reports, and performs SonarQube analysis"
group = "Verification"
dependsOn("testAll", "jacocoTestReportAll")
finalizedBy("sonar")
}
/**
* 로컬용 - SonarQube 분석 없이 빠르게 테스트 커버리지만 확인합니다.
* 사용 예: ./gradlew checkCoverage
*/
tasks.register("checkCoverage") {
description = "Runs tests and generates coverage reports without SonarQube analysis"
group = "Verification"
dependsOn("testAll", "jacocoTestReportAll")
}
/**
* 로컬용 - 빌드 과정에서 생성된 모든 리포트를 삭제합니다.
* 사용 예: ./gradlew cleanReports
*/
tasks.register("cleanReports") {
description = "Cleans all generated reports"
group = "Cleanup"
doLast {
subprojects.forEach { subproject ->
delete(subproject.layout.buildDirectory.dir("reports"))
}
delete(layout.buildDirectory.dir("reports"))
}
}
tasks.register("testAll") {
description = "Runs tests in all subprojects"
group = "Verification"
dependsOn(subprojects.map { it.tasks.named("test") })
}
tasks.register("jacocoTestReportAll") {
description = "Generates JaCoCo test reports for all subprojects and creates aggregate report"
group = "Verification"
dependsOn(subprojects.map { it.tasks.named("jacocoTestReport") })
finalizedBy("jacocoRootReport")
}