[TIL] ๐ŸŒผ24/04/10๐ŸŒผ#Kapt vs Ksp

0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
78/104
post-thumbnail
post-custom-banner

[TIL] ๐ŸŒผ24/04/10๐ŸŒผ#Kapt vs Ksp

Kapt vs Ksp

  • Moshi ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด plugin์„ ์ถ”๊ฐ€ํ•  ๋•Œ,
    kapt๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด build ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ  ksp๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด build๊ฐ€ ์ž˜๋˜์—ˆ๋‹ค.
  • kapt์™€ ksp์˜ ์ฐจ์ด๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์•Œ์•„๋ณด์•˜๋‹ค.

๐Ÿ“Œ์ฐธ๊ณ ์ž๋ฃŒ

Kapt(Kotlin Annotation Processing Tool)

  • a command-line tool, builds plugins for Kotlin
  • process annotations in Kotlin code during build process
  • Kapt์˜ ํŠน์ง•:
    • Annotation processing
    • Code generation
      • generate Kotlin/Java code based on the annotations
      • ๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ ์ฝ”๋“œ ๊ฐ์†Œ
    • Custom Annotations
    • Use cases
      • generate dependency injection frameworks
      • Json ์ง๋ ฌํ™”/์—ญ์ง๋ ฌํ™”
      • database access code
      • API client

Ksp(Kotlin Symbol Processors)

  • designed to improve the performance and ease of annotation processing in Kotlin
  • Ksp์˜ ํŠน์ง•:
    • Performance
    • Kotlin-Centric
    • Kotlin-DSL Integration
      • integrates well with Kotlin DSL(Domain Specific Language)
      • easier to write code generation logic
    • Improved Code Generation
      • allows creation of new symbols & types
  • Ksp ์ง€์› ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ:
    Room, Moshi, RxHttp, Koin, Glide, Auto Dagger, Dagger, Hilt, ๋“ฑ
  • DataBinding์„ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœ์ ํŠธ๋Š” Ksp ์‚ฌ์šฉ ํ•„์š” X
    • DataBinding์€ Kapt ์‚ฌ์šฉ, Ksp ์ง€์› ๊ณ„ํš X

Kapt vs Ksp

  • Configuration
    • Kapt: ๊ธฐ์กด ํ”„๋กœ์ ํŠธ๋“ค๊ณผ integrate ์‰ฌ์›€
    • Ksp: ์ƒˆ๋กœ์šด ํ”„๋กœ์ ํŠธ๋“ค๊ณผ integrate ์‰ฌ์›€
  • Performance
    • Ksp: Kapt๋ณด๋‹ค 2๋ฐฐ ๋” ๋น ๋ฅด๊ณ  ํšจ์œจ์ ์ž„
  • Kotlin-Specific Features
    • Kapt: cannot fully leverage Kotlin-specific features
    • Ksp: more Kotlin-friendly code
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€