DBILITY

android migration kapt to ksp 본문

android/kotlin

android migration kapt to ksp

DBILITY 2024. 3. 29. 10:13
반응형

https://kotlinlang.org/docs/kapt.html#try-kotlin-k2-compiler

 

kapt compiler plugin | Kotlin

 

kotlinlang.org

https://developer.android.com/build/migrate-to-ksp?hl=ko

 

kapt에서 KSP로 이전  |  Android Studio  |  Android Developers

주석 프로세서의 사용을 kapt에서 KSP로 이전합니다.

developer.android.com

kapt는 the Kotlin Annotation Processing Tool의 약자로 Kotlin에서 Java Annotation Processor를 사용하여 Annotation들을 사용할 수 있도록 해준다. 

ksp는 Kotlin Symbol Processing의 약자로 kotlin으로 작성되었으며 kapt와 같은 역할이지만 Kotlin 코드를 직접 분석하기 때문에 빌드 속도가 매우 빠르다.

kotlin 버전을 맞춰야 한다고

room을 사용할때 처음 써봤다.

둘다 해보니 그냥 모르겠다^^

libs.versions.toml (Version Catalog)

[versions]
agp = "8.3.1"
kotlin = "1.9.0"
coreKtx = "1.12.0"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.11.0"
activity = "1.8.2"
constraintlayout = "2.1.4"
room = "2.6.1"
#kapt = "1.9.0"
ksp="1.9.0-1.0.13"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
androidx-room = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
androidx-room-comfiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
#jetbrainsKotlinKapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kapt" }
jetbrainsKotlinKsp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

build.gradle.kts(Project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.jetbrainsKotlinAndroid) apply false
    //alias(libs.plugins.jetbrainsKotlinKapt) apply false
    alias(libs.plugins.jetbrainsKotlinKsp) apply false
}

build.gradle.kts(Module)

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsKotlinAndroid)
    //alias(libs.plugins.jetbrainsKotlinKapt)
    alias(libs.plugins.jetbrainsKotlinKsp)
}

android {
    namespace = "com.dbility.myroom"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.dbility.myroom"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        viewBinding = true
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.activity)
    implementation(libs.androidx.constraintlayout)
    implementation(libs.androidx.room)
    ksp(libs.androidx.room.comfiler)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
}
반응형
Comments