-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
176 lines (157 loc) · 5.07 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
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.9'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
// restdocs
// adoc 파일 변환, build 디렉토리에 복사
id "org.asciidoctor.jvm.convert" version "3.3.2"
// 테스트 결과를 OAS용 yaml 파일로 변환
id "com.epages.restdocs-api-spec" version "0.16.2"
id 'com.google.cloud.tools.jib' version '3.2.1'
}
group = 'sku'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
asciidoctorExt
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set("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-webflux'
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.79.Final:osx-aarch_64'
// swagger(openapi)
implementation("org.springdoc:springdoc-openapi-ui:1.6.11")
implementation("org.springdoc:springdoc-openapi-webmvc-core:1.6.11")
// spring security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation "org.springframework.boot:spring-boot-configuration-processor"
// oauth2
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
// QueryDSL JPA
implementation 'com.querydsl:querydsl-jpa'
implementation 'com.querydsl:querydsl-apt'
// QFile 생성 및 가져오기
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
// restdocs
// mockMvc를 사용해서 snippets을 생성
testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc")
testImplementation("com.epages:restdocs-api-spec:0.16.2")
testImplementation("com.epages:restdocs-api-spec-mockmvc:0.16.2")
asciidoctorExt("org.springframework.restdocs:spring-restdocs-asciidoctor")
}
tasks.named('test') {
outputs.dir snippetsDir
useJUnitPlatform()
}
tasks.register("restDocsTest", Test) { // ./gradlew clean restDocsTest 시 restDocs 파일 생성
outputs.dir snippetsDir
useJUnitPlatform {
includeTags("restDocs")
}
finalizedBy "asciidoctor"
finalizedBy "openapi3"
finalizedBy "bearerAuthentication"
}
tasks.named("asciidoctor") {
configurations 'asciidoctorExt'
baseDirFollowsSourceFile()
inputs.dir snippetsDir
dependsOn restDocsTest
}
openapi3 {
servers = [
{ url = 'http://localhost:8080' },
]
title = 'Moa Moa Swagger + RestDocs API'
description = '이 문서는 RestDocs로 테스트 된 API만 모아둔 문서입니다.\n' +
'아직 개발중인 API와 함께 모아둔 문서를 확인하고 싶으시다면 http://localhost:8080/swagger-ui/index.html 로,\n' +
'RestDocs를 이용한 API 명세서를 확인하고 싶으시다면 http://localhost:8080/docs/index.html 로 접속해주세요.'
version = "${project.version}"
format = 'yaml'
}
tasks.register("bearerAuthentication") {
// epages사의 restdocs-api-spec 라이브러리에는 bearer 설정이 없음, 생성된 yaml 파일에 bearer 설정을 문자열로 추가
doLast {
def apiSpecFile = file('build/api-spec/openapi3.yaml')
def contentToAdd =
" securitySchemes:\n" +
" bearerAuth:\n" +
" type: http\n" +
" scheme: bearer\n" +
" bearerFormat: JWT\n" +
"\n"+
"security:\n" +
" - bearerAuth: []"
def existingContent = apiSpecFile.text
def updatedContent = existingContent + contentToAdd
apiSpecFile.write(updatedContent)
}
}
tasks.register("apiBuild", GradleBuild) { // ./gradlew apiBuild 시 restdocs 생성 후 build
tasks = ["clean", "restDocsTest", "build"]
}
tasks.named("bootBuildImage") { // ./gradlew bootBuildImage 시 docker hub로 배포
imageName = project.DOCKER_ID + "/" + project.DOCKER_IMAGE_NAME
publish = true
docker {
publishRegistry {
username = project.DOCKER_ID
password = project.DOCKER_PW
}
}
}
jib {
from {
image = "openjdk:11-jre-slim"
auth {
username = project.DOCKER_ID
password = project.DOCKER_PW
}
}
to {
image = project.DOCKER_ID + "/" + project.DOCKER_IMAGE_NAME
auth {
username = project.DOCKER_ID
password = project.DOCKER_PW
}
tags = ["latest"]
}
container {
jvmFlags = ["-Xms128m", "-Xmx128m"]
}
}
bootJar {
from("swagger-ui") {
into "BOOT-INF/classes/static/swagger"
}
from("${asciidoctor.outputDir}") {
into "BOOT-INF/classes/static/docs"
}
from("build/api-spec") {
into "BOOT-INF/classes/static/swagger"
}
archiveFileName.set "moamoa.jar"
}
springBoot {
buildInfo()
}