-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
223 lines (191 loc) · 6.2 KB
/
build.gradle
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
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.6'
id 'jacoco'
id "org.sonarqube" version "4.0.0.2929"
id "org.asciidoctor.jvm.convert" version "3.3.2"
id 'com.epages.restdocs-api-spec' version '0.17.1'//restdocs -> swagger
id 'org.hidetake.swagger.generator' version '2.18.2'
}
group = 'com.letscareer'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
asciidoctorExt
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2023.0.0")
snippetsDir = file('build/generated-snippets') // 스니펫이 생성되는 디렉터리 경로를 설정
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// openfeign
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'io.github.openfeign:feign-okhttp'
// 스프링부트 3.xx에서는 p6spy 버전 1.9.0 사용해야됨
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.jsoup:jsoup:1.17.2'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.h2database:h2'
//restdocs-api-spec 의존성 추가
testImplementation 'com.epages:restdocs-api-spec-mockmvc:0.19.2'
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'com.squareup.okhttp3:mockwebserver'
// Querydsl 추가
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
sourceSets {
test {
java {
srcDirs = ['src/test/java']
}
}
}
def serverUrl = "http://localhost:8080"
if (project.hasProperty("spring.profiles.active")) {
def activeProfile = project.property("spring.profiles.active")
if (activeProfile == "prod") {
serverUrl = System.getProperty('PROD_SERVER_URL') ?: "https://default.prod.server.url"
} else if (activeProfile == "local") {
serverUrl = "http://localhost:8080"
}
}
// openapi3 설정
openapi3 {
server = serverUrl
title = "위대한레츠비 API 문서"
description = "Spring REST Docs with SwaggerUI."
version = "0.0.1"
outputFileNamePrefix = 'open-api-3.0.1'
format = 'json'
outputDirectory = 'build/resources/main/static/docs'
}
// GenerateSwaggerUI 태스크가 openapi3 태스크에 의존하도록 설정
tasks.withType(GenerateSwaggerUI).configureEach {
dependsOn 'openapi3'
// 기존 파일 삭제 후 json 파일 복사
delete file('src/main/resources/static/docs/')
copy {
from "build/resources/main/static/docs"
into "src/main/resources/static/docs/"
}
}
// 테스트를 통해 생성된 snippets 출력 위치 정의
tasks.register("ext") {
snippetsDir = file('build/generated-snippets')
}
tasks.named('test') {
useJUnitPlatform()
outputs.dir 'snippetsDir' // test 스니펫 디렉터리를 출력으로 추가하도록 작업을 구성
finalizedBy 'jacocoTestReport' // test가 끝나면 jacocoTestReport 동작
// 파일 생성 로직 추가
doFirst {
def docsDir = file('build/resources/main/static/docs')
if (!docsDir.exists()) {
docsDir.mkdirs()
}
def apiFile = file('build/resources/main/static/docs/open-api-3.0.1.json')
if (!apiFile.exists()) {
apiFile.createNewFile()
}
}
}
// 기존에 존재하던 docs 삭제
asciidoctor.doFirst {
delete file('src/main/resources/static/docs')
}
// asciidoctor 작업을 구성
tasks.named("asciidoctor") {
inputs.dir 'snippetsDir'
configurations 'asciidoctorExt'
dependsOn test
}
tasks.named("bootJar") {
dependsOn asciidoctor
from("${asciidoctor.outputDir}") {
into 'static/docs'
}
dependsOn(':openapi3')
}
tasks.register('copyDocument', Copy) {
dependsOn asciidoctor
from file("$buildDir/docs/asciidoc")
into file("src/main/resources/static/docs")
}
tasks.named("build") {
dependsOn copyDocument
}
// jacoco report 설정
jacocoTestReport {
dependsOn compileJava
dependsOn processResources
// 제외할 패키지 또는 클래스 설정
def excludedPackages = [
'**/global/**', // global 패키지 제외
'**/dto/**', // dto 패키지 제외
'**/handler/**', // handler 패키지 제외
'**/model/**', // model 패키지 제외
'**/config/**', // config 패키지 제외
'**/common/**', // common 패키지 제외
]
// 포함할 패키지 설정
def includedPackages = [
'com/boosting/**/application/**' // application 패키지 포함
]
// 클래스 디렉토리 설정
getClassDirectories().setFrom(
files(classDirectories.files.collect {
fileTree(dir: it, include: includedPackages, exclude: excludedPackages)
})
)
reports {
xml.required = true
xml.outputLocation = file("$buildDir/reports/jacoco/test/jacocoTestReport.xml")
// html로 report 생성하기
// 빌드경로/jacoco/report.html 폴더 내부로 경로 설정
html.required = true
html.outputLocation = file("$buildDir/reports/jacoco/test/html")
}
// jacocoTestReport가 끝나면 jacocoTestCoverageVerification 동작
finalizedBy 'jacocoTestCoverageVerification'
}
// jacoco 커버리지 검증 설정
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.0 // 최소 커버리지 비율 설정 (예: 80%)
}
}
}
}