-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
102 lines (76 loc) · 4.17 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
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.7'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.solux.pyi'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
// build.gradle 내부에서 사용되는 설정을 정의한다.
configurations {
//lombok 설정 추가
compileOnly {
// 여기서는 compileOnly가 annotationProcessor를 상속하도록 설정했다.
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// lombok 라이브러리
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
// lombok 테스트 라이브러리
testImplementation 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
// 프로젝트에 Spring Data Jpa 적용
// spring-boot-starter-data-jpa
// - 스프링 부트용 Spring Data Jpa 추상화 라이브러리
// - 스프링 부트 버전에 맞춰 자동으로 JPA 관련 라이브러리들의 버전을 관리
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// h2
// - 인메모리 관계형 데이터베이스
// - 별도의 설치가 필요 없이 프로젝트 의존성만으로 관리할 수 있다.
// - 메모리에서 실행되기 때문에 애플리케이션을 재시작할 때마다 초기화된다는 점을 이용하여 테스트 용도로 많이 사용
// - 이 책에서는 JPA의 테스트, 로컬 환경에서의 구동에서 사용할 예정
implementation 'com.h2database:h2'
// session
implementation 'org.springframework.session:spring-session-jdbc'
// 애플리케이션을 실행해서 로그인을 테스트한 뒤, h2-console로 접속한다.
// h2-console을 보면 세션을 위한 테이블 2개(SPRING_SESSION, SPRING_SESSION_ATTRIBUTES)가 생성된 것을 볼 수 있다.
// JPA로 인해 세션 테이블이 자동 생성되었기 때문에 별도로 해야 할 일은 없다.
// 방금 로그인했기 때문에 한 개의 세션이 등록돼있는 것을 볼 수 있다.
// 세션 저장소를 데이터베이스로 교체했다.
// 물론 지금은 기존과 동일하게 스프링을 재시작하면 세션이 풀린다.
// 이유는 H2 기반으로 스프링이 재실행될 때 H2도 재시작되기 때문이다.
// 이후 AWS로 배포하게 되면 AWS의 데이터베이스 서비스인 RDS(Relational Database Service)를 사용하게 되니 이때부터는 세션이 풀리지 않는다.
// 먼저 MariaDB 드라이버를 build.gradle에 등록한다.
// 현재는 H2 드라이버만 있는 상태이다.
implementation 'org.mariadb.jdbc:mariadb-java-client'
// spring security
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
//implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
// - 소셜 로그인 등 클라이언트 입장에서 소셜 기능 구현 시 필요한 의존성
// - spring-security-oauth2-client와 spring-security-oauth2-jose를 기본으로 관리해준다.
// "Posts_등록된다"의 테스트 로그로 응답의 결과로 200(정상 응답) Status Code를 원했는데 결과는 302(리다이렉션 응답) Status Code가 와서 실패했다.
// 이는 스프링 시큐리티 설정 때문에 인증되지 않은 사용자의 요청은 이동시키기 때문이다.
// 그래서 이런 API 요청은 임의로 인증된 사용자를 추가하여 API만 테스트해 볼 수 있게 한다.
// 어려운 방법은 아니며, 이미 스프링 시큐리티에서 공식적으로 방법을 지원하고 있다.
// 스프링 시큐리티 테스트를 위한 여러 도구를 지원하는 spring-security-test를 build.gradle에 추가한다.
testImplementation 'org.springframework.security:spring-security-test'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-hibernate5'
}
tasks.named('test') {
useJUnitPlatform()
}
//// 배포 관련
//jar {
// enabled=false
//}