Skip to content

Latest commit

ย 

History

History
112 lines (92 loc) ยท 4.12 KB

File metadata and controls

112 lines (92 loc) ยท 4.12 KB

ktargeter buildMaven Central GitHub License

English | ํ•œ๊ตญ์–ด

ktargeter logo

Ktargeter๋Š” properties์„ ์œ„ํ•œ annotation use-site targets๋ฅผ ์žฌ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” Kotlin ์ปดํŒŒ์ผ๋Ÿฌ ํ”Œ๋Ÿฌ๊ทธ์ธ์ž…๋‹ˆ๋‹ค. Kotlin ์ฝ”๋“œ์—์„œ Java annotation๋“ค์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ข…์ข… use-site targets์„ ์ง€์ •ํ•ด์•ผ ํ•˜๋Š”๋ฐ, ์ด๋Š” ๋ถˆํŽธํ•  ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ target์ด ์ง€์ •๋˜์ง€ ์•Š์•˜์„ ๋•Œ ๋Ÿฐํƒ€์ž„ ๋ฒ„๊ทธ๋กœ ์ด์–ด์ง‘๋‹ˆ๋‹ค. Ktargeter๋Š” ์—ฌ๋Ÿฌ๋ถ„์ด @get:Email, @field:Email, ๋˜๋Š” @set:Email์„ ๋ชจ๋‘ ๊ธฐ์–ตํ•˜๋Š” ๋Œ€์‹ ์—, Gradle์—์„œ ๋‹จ ํ•œ ๋ฒˆ๋งŒ ๊ตฌ์„ฑํ•˜๋ฉด ์ฝ”๋“œ ์ „์ฒด์—์„œ @Email์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค. Ktargeter๋Š” ์ปดํŒŒ์ผ ์ค‘์— ์ž‘๋™ํ•˜๋ฉฐ, ๋Ÿฐํƒ€์ž„ ์ค‘์— ์ถ”๊ฐ€ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ์—ฌ๋Ÿฌ๋ถ„์€ ์ด ์ฝ”๋“œ๋ฅผ:

data class User(
    @get:One
    val firstName: String,
    @field:Two
    val lastName: String,
    @set:Three
    var birthday: LocalDate,     
)

์ด๋ ‡๊ฒŒ ๊ณ ์น  ์ˆ˜ ์žˆ๊ฒ ์ฃ :

data class User(
    @One
    val firstName: String,
    @Two
    val lastName: String,
    @Three
    var birthday: LocalDate,     
)

์‚ฌ์šฉ

Kotlin 1.5 ํ˜น์€ ์ดํ›„ ๋ฒ„์ „(๋˜๋Š” Kotlin 1.4 with JVM IR backend enabled).

ktargeter๋ฅผ build.gradle์˜ plugins๋ถ€๋ถ„์— ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•:

plugins {
    id 'org.ktargeter' version '0.3.0'
}

์ƒˆ target์˜ annotation์„ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•:

ktargeter.annotations = [
        "com.sample.annotations.One"  : "get",
        "com.sample.annotations.Two"  : "field",
        "com.sample.annotations.Three": "set"
]

์ง€์ •๋œ annotation๋“ค์„ properties์— ์‚ฌ์šฉํ•  ๋•Œ, ์ด annotation์— ๋Œ€ํ•œ use-site targets์„ ์žฌ์ •์˜ํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์ž…๋‹ˆ๋‹ค.

Ktargeter๋Š” target์„ ๋ช…์‹œ์ ์œผ๋กœ ์ง€์ •ํ•˜๋Š” annotations์˜ target๋“ค์„ ์žฌ์ •์˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Compatibility

Pick a plugin version depending on the Kotlin version used in your project.

Kotlin version Ktargeter version
Kotlin 1.6 or newer Ktargeter 0.3.0
Kotlin 1.5 Ktargeter 0.2.1
Kotlin 1.4 Ktargeter 0.1.0

๊ธฐ์—ฌ

๋ฒ„๊ทธ๋ฅผ ๋ฐœ๊ฒฌํ–ˆ๊ฑฐ๋‚˜, Ktargeter๋ฅผ ๊ฐœ์„ ํ•  ์•„์ด๋””์–ด๊ฐ€ ์žˆ์œผ๋ฉด ์–ธ์ œ๋“ ์ง€ issue๋ฅผ ํ†ตํ•ด ๊ธฐ์—ฌํ•ด์ฃผ์„ธ์š”. ๋˜๋Š” Pull Request๋ฅผ ํ†ตํ•ด ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ œ์•ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ •

Ktargeter๋ฅผ ๋””๋ฒ„๊ทธ ๋˜๋Š” ๊ฐœ๋ฐœํ•œ๋‹ค๋ฉด ๋‹ค์Œ์˜ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด์ฃผ์„ธ์š”:

  1. Gradle ๋ฐ Kotlin ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๋กœ์ปฌ Maven ์ €์žฅ์†Œ์— ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.:
./gradlew publishToMavenLocal -x signMavenPublication \
 -x signPluginMavenPublication -x signSimplePluginPluginMarkerMavenPublication
  1. ํ”„๋กœ์ ํŠธ๋ฅผ IntelliJ IDEA('Debug Kotlin Plugin' ํ™˜๊ฒฝ)์—์„œ Importํ•ฉ๋‹ˆ๋‹ค.

    • Run/Debug Configuration ์ฐฝ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  2. 'compiler-plugin' ๋ชจ๋“ˆ์˜ ํด๋ž˜์Šค์— ์ค‘๋‹จ์ ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

  3. ๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ณต์ œ ๋ฐ ๋นŒ๋“œํ•ฉ๋‹ˆ๋‹ค. (์ƒ˜ํ”Œ ํ”„๋กœ์ ํŠธ):

./gradlew clean build --no-daemon -Dorg.gradle.debug=true \
 -Dkotlin.compiler.execution.strategy="in-process" \
 -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
  1. Debug Kotlin Plugin๊ตฌ์„ฑ์„ ๋””๋ฒ„๊น… ๋ชจ๋“œ์—์„œ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค..