Compose 컴파일러 Gradle 플러그인 설정

Gradle 사용자는 Compose Compiler Gradle 플러그인을 사용하여 Compose를 더 쉽게 설정하고 구성할 수 있습니다.

Gradle 버전 카탈로그로 설정

다음 안내에서는 Compose Compiler Gradle 플러그인을 설정하는 방법을 설명합니다.

  1. libs.versions.toml 파일에서 Compose 컴파일러에 대한 모든 참조를 삭제합니다.
  2. 플러그인 섹션에 다음 새 종속 항목을 추가합니다.
[versions]
kotlin = "2.0.0"

[plugins]
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

// Add this line
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
  1. 프로젝트 루트 build.gradle.kts 파일의 플러그인 섹션에 다음 스니펫을 추가합니다.
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler) apply false
}
  1. Compose를 사용하는 각 모듈에서 다음과 같이 플러그인을 적용합니다.
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler)
}

기본 설정을 사용하는 경우 이제 앱이 빌드되고 컴파일됩니다. Compose 컴파일러에서 맞춤 옵션을 구성한 경우 다음 섹션을 참고하세요.

Gradle 버전 카탈로그 없이 Compose 컴파일러 설정

Compose를 사용하는 모듈과 연결된 build.gradle.kts 파일에 다음 플러그인을 추가합니다.

plugins {
    id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" // this version matches your Kotlin version
}

최상위 프로젝트 build.gradle.kts 파일에 이 클래스 경로를 추가해야 할 수도 있습니다.

buildscript {
    dependencies {
        classpath("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:2.0.0")
    }
}

Compose 컴파일러 Gradle 플러그인의 구성 옵션

Gradle 플러그인을 사용하여 Compose 컴파일러를 구성하려면 최상위 수준에서 모듈의 build.gradle.kts 파일에 composeCompiler 블록을 추가합니다.

android {  }

composeCompiler {
    reportsDestination = layout.buildDirectory.dir("compose_compiler")
    stabilityConfigurationFile = rootProject.layout.projectDirectory.file("stability_config.conf")
}

사용 가능한 옵션의 전체 목록은 문서를 참고하세요.

Compose 종속 항목 설정

앱의 build.gradle 파일에 다음 정의를 추가합니다.

Groovy

android {
    buildFeatures {
        compose true
    }
}

Kotlin

android {
    buildFeatures {
        compose = true
    }
}

Android BuildFeatures 블록 내에서 compose 플래그를 true로 설정하면 Android 스튜디오에서 Compose 기능이 사용 설정됩니다.

마지막으로 Compose BOM과 필요한 Compose 라이브러리 종속 항목의 하위 집합을 다음 블록의 종속 항목에 추가합니다.

Groovy

dependencies {

    def composeBom = platform('androidx.compose:compose-bom:2026.01.01')
    implementation composeBom
    androidTestImplementation composeBom

    // Choose one of the following:
    // Material Design 3
    implementation 'androidx.compose.material3:material3'
    // or skip Material Design and build directly on top of foundational components
    implementation 'androidx.compose.foundation:foundation'
    // or only import the main APIs for the underlying toolkit systems,
    // such as input and measurement/layout
    implementation 'androidx.compose.ui:ui'

    // Android Studio Preview support
    implementation 'androidx.compose.ui:ui-tooling-preview'
    debugImplementation 'androidx.compose.ui:ui-tooling'

    // UI Tests
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'

    // Optional - Add window size utils
    implementation 'androidx.compose.material3.adaptive:adaptive'

    // Optional - Integration with activities
    implementation 'androidx.activity:activity-compose:1.11.0'
    // Optional - Integration with ViewModels
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.5'
    // Optional - Integration with LiveData
    implementation 'androidx.compose.runtime:runtime-livedata'
    // Optional - Integration with RxJava
    implementation 'androidx.compose.runtime:runtime-rxjava2'

}

Kotlin

dependencies {

    val composeBom = platform("androidx.compose:compose-bom:2026.01.01")
    implementation(composeBom)
    androidTestImplementation(composeBom)

    // Choose one of the following:
    // Material Design 3
    implementation("androidx.compose.material3:material3")
    // or skip Material Design and build directly on top of foundational components
    implementation("androidx.compose.foundation:foundation")
    // or only import the main APIs for the underlying toolkit systems,
    // such as input and measurement/layout
    implementation("androidx.compose.ui:ui")

    // Android Studio Preview support
    implementation("androidx.compose.ui:ui-tooling-preview")
    debugImplementation("androidx.compose.ui:ui-tooling")

    // UI Tests
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-test-manifest")

    // Optional - Add window size utils
    implementation("androidx.compose.material3.adaptive:adaptive")

    // Optional - Integration with activities
    implementation("androidx.activity:activity-compose:1.11.0")
    // Optional - Integration with ViewModels
    implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.5")
    // Optional - Integration with LiveData
    implementation("androidx.compose.runtime:runtime-livedata")
    // Optional - Integration with RxJava
    implementation("androidx.compose.runtime:runtime-rxjava2")

}