<aside> <img src="/icons/gradebook_purple.svg" alt="/icons/gradebook_purple.svg" width="40px" />
학습 목표
spring-boot-dependencies
BOM 체계를 기반으로, 필요에 따라 특정 라이브러리의 버전을 오버라이딩하는 실전 방법과 주의사항을 설명할 수 있다.
</aside>Spring Boot Starter는 여러 하위 라이브러리를 포함하는 **메타 의존성(Meta Dependency)**이기 때문에, 불필요한 하위 라이브러리가 함께 따라오는 경우가 발생할 수 있다. Gradle에서는 exclude
블록을 활용하여 이러한 하위 라이브러리를 제외하거나, 원하는 구현체로 대체할 수 있다.
<aside> 💡
기본 로깅 구현체(Logback) 제거 예시
</aside>
Spring Boot는 기본적으로 spring-boot-starter-logging
을 통해 SLF4J + Logback을 포함한다. 만약 이 로깅 시스템이 필요 없거나 Log4j2 등 다른 로깅 시스템을 사용하려면 이 기본 의존성을 제거해야 한다.
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
}
exclude group
키워드와 제거할 module
을 명시하여 의존성 트리에서 명확히 제거
Gradle에서는 이렇게 선언된 exclude
가 transitive dependency까지 적용됨
→ Transitive dependency(전이적 종속성) : 내가 직접 추가하지 않았지만, 내가 추가한 라이브러리가 필요로 해서 함께 포함되는 간접적인 의존성
<aside> 💡
기본으로 제공되는 구현체를 사용자 정의 라이브러리나 최신 버전으로 교체
</aside>
예: Jackson → Gson
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
implementation 'com.google.code.gson:gson:2.10.1'
}
참고로, 위에서 예시로 든 Jackson을 제외하면 Spring MVC의 기본 JSON 직렬화 기능이 사라지므로HttpMessageConverter
또는 WebMvcConfigurer
를 통해 Gson 설정을 수동으로 적용해야 함.
예: Hibernate → EclipseLink
JPA를 사용할 때, 기본 구현체(Hibernate)를 다른 구현체로 바꾸는 경우도 가능함
dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'org.hibernate', module: 'hibernate-core'
}
im*plementation 'org.eclipse.persistence:eclipselink:3.0.2'
}*
하위 의존성이 다시 끌고 오는 경우
dependencies {
// b 패키지에 y 의존성을 제거
implementation('a:b') {
exclude group: 'x', module: 'y'
}
// 만약 d 패키지에도 y 의존성이 존재한다면 다시 참조될 수 있으므로 중복 제거해줘야 함
implementation('c:d') {
exclude group: 'x', module: 'y'
}
}
애플리케이션 동작 중 오류 발생 가능성
./gradlew dependencies
로 의존성 트리를 정확히 분석한 뒤, 적용해야 함