[SIDE] 프로젝트 세팅

danbi lee·2024년 10월 24일

의존성 설정

dependencies {
    // Spring Boot Core
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-security")

    // Kotlin
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")

    // Redis
    implementation("org.springframework.boot:spring-boot-starter-data-redis")

    // Validation
    implementation("org.springframework.boot:spring-boot-starter-validation")

    // Development tools
    developmentOnly("org.springframework.boot:spring-boot-devtools")

    // Database
    runtimeOnly("org.postgresql:postgresql")

    // Testing
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
    testImplementation("org.springframework.security:spring-security-test")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
    testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
    testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
}

필수 의존성

Spring Boot

  1. Spring Web: RESTful API와 웹 애플리케이션을 만들기 위한 기본 의존성.
    implementation("org.springframework.boot:spring-boot-starter-web")
  2. Spring Data JPA: 데이터베이스와 상호작용하기 위한 ORM(객체 관계 매핑) 라이브러리.
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
  3. Spring Security: JWT 기반 인증 및 권한 관리를 위한 필수 의존성.
    implementation("org.springframework.boot:spring-boot-starter-security")
  4. Spring Boot DevTools: 개발 중에 유용한 도구로, 코드 변경 시 애플리케이션을 자동으로 재시작하는 기능 제공.
    developmentOnly("org.springframework.boot:spring-boot-devtools")

Kotlin

  1. Kotlin Standard Library: Kotlin 프로젝트에서 기본적으로 사용하는 표준 라이브러리.
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
  2. Kotlin Reflect: 리플렉션을 사용할 때 필요한 의존성 (Spring에서 Kotlin과 함께 필수).
    implementation("org.jetbrains.kotlin:kotlin-reflect")
  3. jackson-module-kotlin: JSON 데이터의 직렬화 및 역직렬화를 처리하는 라이브러리.
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")

데이터베이스 및 실시간 관련

  1. PostgreSQL Driver: PostgreSQL 데이터베이스와 연결하기 위한 의존성.
    implementation("org.postgresql:postgresql")
  2. Redis: 실시간 데이터 처리를 위한 Redis 클라이언트.
    implementation("org.springframework.boot:spring-boot-starter-data-redis")

JWT

  1. jjwt-api: JWT 토큰을 생성하고, 서명하고, 파싱하기 위한 핵심 API.
    implementation("io.jsonwebtoken:jjwt-api:$jwtVersion")
  2. jjwt-impl: JWT의 구체적인 구현체입니다. 토큰 생성과 검증을 처리.
    implementation("io.jsonwebtoken:jjwt-impl:$jwtVersion")
  3. jjwt-jackson: Jackson과 통합하여 JWT의 직렬화/역직렬화 지원.
    implementation("io.jsonwebtoken:jjwt-jackson:$jwtVersion")

테스트 관련

  1. Kotest: Kotlin 프로젝트에서 테스트를 위한 프레임워크.
    testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
    testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
    testImplementation("io.kotest.extensions:kotest-extensions-spring:$kotestVersion")
    testImplementation("io.kotest:kotest-property:$kotestVersion")
  2. MockK: Kotlin에서 사용하는 모킹 라이브러리 (Mockito와 비슷한 역할).
    testImplementation("io.mockk:mockk")

추가적으로 고려할 의존성

  1. Validation: 데이터 유효성 검사를 위한 의존성.
    implementation("org.springframework.boot:spring-boot-starter-validation")
  2. Swagger/OpenAPI: API 문서화를 위한 Swagger 의존성.
    implementation("org.springdoc:springdoc-openapi-ui:1.5.10")

의존성 범위

의존성의 사용 시점에 따라 나뉨.
프로젝트에서 특정 라이브러리가 어떤 단계에서 필요한지를 명확히 하여, 불필요한 라이브러리들이 잘못된 시점에 포함되는 것을 방지하는 역할이다.

  • implementation: 컴파일과 실행 모두 포함
  • developmentOnly: 개발 중에만 필요, 배포 시 포함되지 않음
  • runtimeOnly: 실행 시에만 필요, 컴파일 시에는 필요 없음
  • testImplementation: 테스트 컴파일 및 실행 시점에만 필요
  • testRuntimeOnly: 테스트 실행 시에만 필요, 컴파일 시에는 필요 없음

패키지 구조 설정

패키지를 기능별로 나누어 설계하는 것이 유지보수와 확장성에 좋다.

com
 └── test
      ├── config            // 설정 관련 클래스 (Security, CORS, etc.)
      ├── controller        // REST API 컨트롤러 (Controller 계층)
      ├── dto               // 데이터 전송 객체 (Data Transfer Object)
      ├── entity            // JPA 엔티티 클래스 (데이터베이스 테이블 매핑)
      ├── repository        // 데이터베이스 액세스 레이어 (JPA Repository)
      ├── service           // 비즈니스 로직 계층 (Service 계층)
      ├── exception         // 예외 처리 관련 클래스
      └── security          // JWT, 인증/인가 관련 클래스

데이터베이스 연결

PostgreSQL 데이터베이스와 연결하려면, application.yml 또는 application.properties 파일에 데이터베이스 연결 정보를 추가해야 한다.

application,properties

spring.datasource.url=jdbc:postgresql://localhost:5432/your_database_name
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=org.postgresql.Driver

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

엔티티 클래스 생성

CI/CD 파이프라인 구축


https://kotest.io/docs/quickstart/#test-framework

profile
계속해서 보완중

0개의 댓글