μ•ˆλ…•ν•˜μ„Έμš” Mambo μž…λ‹ˆλ‹€.

μ˜€λŠ˜μ€ κ·Έλž˜λ“€ λ©€ν‹° λͺ¨λ“ˆ ν”„λ‘œμ νŠΈμ˜ λ””νŽœλ˜μ‹œ κ³΅μœ μ— λŒ€ν•˜μ—¬ 이야기 해보렀고 ν•©λ‹ˆλ‹€.

κ·Έλž˜λ“€ λ©€ν‹° λͺ¨λ“ˆ

μ„œλΉ„μŠ€μ˜ 규λͺ¨κ°€ μ–΄λŠμ •λ„ μ»€μ§€κ²Œλ˜λ©΄ λͺ¨λ†€λ¦¬μ‹ μ•„ν‚€ν…μ²˜λ‘œμ¨ μ„œλΉ„μŠ€μ— λŒ€ν•œ λͺ¨λ“  κΈ°λŠ₯이 ν•˜λ‚˜μ˜ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— κ΅¬ν˜„ν•˜λŠ” 것을 λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€ μ•„ν‚€ν…μ²˜λ₯Ό μ°Έκ³ ν•˜μ—¬ 일뢀 κΈ°λŠ₯을 μˆ˜ν–‰ν•˜λŠ” λ³„λ„μ˜ μ• ν”Œλ¦¬μΌ€μ΄μ…˜λ‘œ λ…λ¦½μ‹œν‚€κΈ°λ„ ν•©λ‹ˆλ‹€. ν˜„μž¬ λ‹€λ‹ˆκ³  μžˆλŠ” νšŒμ‚¬μ—μ„œλŠ” λͺ¨λ†€λ¦¬μ‹ μ•„ν‚€ν…μ²˜λ‘œ κ°œλ°œν•˜κ³  μžˆλŠ” μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ μ—¬λŸ¬ κ³ κ°λ“€μ˜ ν™˜κ²½μ— λ§žλŠ” 배포 λ˜λŠ” λ³„λ„μ˜ μ»€μŠ€ν…€ κΈ°λŠ₯을 μ§€μ›ν•˜κΈ° μœ„ν•˜μ—¬ κ·Έλž˜λ“€ λ©€ν‹° λͺ¨λ“ˆ ν”„λ‘œμ νŠΈλ‘œ μ „ν™˜ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

Java 라이브러리 ν”ŒλŸ¬κ·ΈμΈ

곡용 λͺ¨λ“ˆμ—μ„œ μ‚¬μš©ν•˜λŠ” λ””νŽœλ˜μ‹œλ₯Ό μƒμœ„ λͺ¨λ“ˆμ—μ„œλ„ μ‚¬μš©ν•˜κΈ° μœ„ν•΄μ„œλŠ” μžλ°” ν”ŒλŸ¬κ·ΈμΈ λŒ€μ‹  μžλ°” 라이브러리 ν”ŒλŸ¬κ·ΈμΈμ„ μ μš©ν•˜κ³  apiλ₯Ό μ‚¬μš©ν•˜μ—¬ μ§€μ •λœ λ””νŽœλ˜μ‹œλ₯Ό μ™ΈλΆ€ λͺ¨λ“ˆμ˜ 컴파일 ν΄λž˜μŠ€νŒ¨μŠ€μ— λ…ΈμΆœμ‹œμΌœμ•Όν•©λ‹ˆλ‹€. Gradle 7 λΆ€ν„°λŠ” compile을 μ§€μ›ν•˜μ§€ μ•ŠμœΌλ©° implementation은 μ§€μ •ν•œ λ””νŽœλ˜μ‹œλ₯Ό μ™ΈλΆ€ λͺ¨λ“ˆμ— λ…ΈμΆœμ‹œν‚€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

The compile and runtime configurations have been removed with Gradle 7.0. Please refer to the upgrade guide how to migrate to implementation and api configurations`.

// module-common/build.gradle
plugins {
    id 'java-library'
    id 'io.spring.dependency-management'
}

dependencies {
    api 'com.google.code.gson:gson'
}

common λͺ¨λ“ˆμ˜ gson λΌμ΄λΈŒλŸ¬λ¦¬λŠ” apiλ₯Ό 톡해 μƒμœ„ λͺ¨λ“ˆμ˜ ν΄λž˜μŠ€νŒ¨μŠ€μ— λ…ΈμΆœλ˜μ–΄ μƒμœ„ λͺ¨λ“ˆμ—μ„œλ„ μ‚¬μš©μ΄ κ°€λŠ₯ν•΄μ§‘λ‹ˆλ‹€. 기본적으둜 implementation을 μ‚¬μš©ν•˜λŠ” 경우 μ™ΈλΆ€ λͺ¨λ“ˆ ν΄λž˜μŠ€νŒ¨μŠ€μ— λ…ΈμΆœμ‹œν‚€μ§€ μ•ŠλŠ” μ΄μœ λŠ” λΉ λ₯Έ 컴파일과 클래슀패슀 μ‚¬μ΄μ¦ˆλ₯Ό 쀄이기 μœ„ν•¨μ΄λ©° api λ³΄λ‹€λŠ” implementation을 μ„ ν˜Έν•΄μ•Όν•œλ‹€κ³  ν•©λ‹ˆλ‹€.

Common Module

gradle-multi-module 처럼 κ·Έλž˜λ“€ λ©€ν‹° λͺ¨λ“ˆ ν”„λ‘œμ νŠΈμ— 곡용으둜 μ μš©λ˜λŠ” μ½”λ“œλ₯Ό κ°€μ§€λŠ” Common λͺ¨λ“ˆμ΄ μžˆμ„λ•Œ λ‹€μŒκ³Ό 같이 κ³΅ν†΅μœΌλ‘œ μ μš©λ˜μ–΄μ•Όν•˜λŠ” 섀정을 μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@Configuration(proxyBeanMethods = false)
public class JsonConfig {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer objectMapperBuilderCustomizer() {
        return builder -> builder
                .featuresToEnable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                .featuresToDisable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
                .modules(List.of(new Jdk8Module(), new JavaTimeModule()));
    }

}

μœ„ μ½”λ“œμ—μ„œλŠ” Date λ˜λŠ” Timestamp와 같은 ν΄λž˜μŠ€μ— λŒ€ν•˜μ—¬ Long κ°’μœΌλ‘œ λ³€ν™˜ν•˜λŠ” κΈ°λŠ₯을 ν™œμ„±ν™”ν•˜κΈ° μœ„ν•˜μ—¬ SerializationFeature.WRITE_DATES_AS_TIMESTAMPSλ₯Ό μ μš©ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

Common Dependencies

plugins {
    id 'java-library'
}

dependencies {
    api 'org.springframework.boot:spring-boot-starter-security'
    api 'com.google.code.gson:gson'
    api 'com.fasterxml.jackson.core:jackson-databind'
    api 'org.hibernate.validator:hibernate-validator'
    api 'org.apache.commons:commons-lang3'
    api 'org.apache.commons:commons-collections4:4.4'
    api 'com.google.guava:guava:31.0.1-jre'
}

μœ„ μ„€μ •μ²˜λŸΌ implementation λŒ€μ‹ μ— apiλ₯Ό μ‚¬μš©ν•˜λ©΄ λ™μΌν•œ λ²„μ „μ˜ λ””νŽœλ˜μ‹œλ₯Ό λ‹€λ₯Έ μ™ΈλΆ€ λͺ¨λ“ˆμ—μ„œλ„ μ‚¬μš©ν•  수 μžˆλ„λ‘ ν΄λž˜μŠ€νŒ¨μŠ€μ— λ…ΈμΆœν•  수 μžˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό 톡해 각 λͺ¨λ“ˆμ—μ„œ μ‚¬μš©λ˜λŠ” λ””νŽœλ˜μ‹œ 버전이 λ‹¬λΌμ„œ λ°œμƒν•  수 μžˆλŠ” 문제λ₯Ό 방지할 수 있게 λ©λ‹ˆλ‹€.

μ°Έκ³