Hanbit the Developer
[Android] Cleaning gradle using KTS(Kotlin DSL), Version Catalogs(toml) 본문
Android
[Android] Cleaning gradle using KTS(Kotlin DSL), Version Catalogs(toml)
hanbikan 2023. 3. 8. 16:56KTS and version catalog make our gradle file clear. And KTS's mainly used in modern android projects like Sunflower, nowinandroid.
I used them to clear my gradle files and to practice Kotlin DSL. Let's see below images. The left one is my old gradle file, and the right one is the new one.
This article covers how I migrated gradle files using KTS, version catalog.
Migrating to KTS
1. Rename gradle files with '.kts' extension.
build.gradle -> build.gradle.kts
setting.gradle -> setting.gradle.kts
2. Modify the kts files.
I had to make those files for 'KTS rule'. The contents of the rule is here.
Using toml(version catalog)
1. Setup for toml
I added the below code to use toml file in setting.gradle.kts.
versionCatalogs {
create("libs") {
from(files("libs.versions.toml"))
}
}
2. Write libs.versions.toml
Let's assume that we have the below code in our gradle file.
implementation("androidx.activity:activity-compose:1.4.0")
Write some codes in libs.versions.toml like:
[versions]
activityCompose = "1.4.0"
// ...
[libraries]
"activity-compose" = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
// ...
Then you can finally simplify the implementation code like below.
implementation(libs.activity.compose)
'Android' 카테고리의 다른 글
Android Lifecycle 분석 (0) | 2023.10.30 |
---|---|
[Kotlin] Coroutines 예외 처리 방법 비교 (0) | 2023.08.28 |
Why is @get:Rule used instead of @Rule in Kotlin? (0) | 2023.02.23 |
Android Library FiveStarsView has been released. (0) | 2023.02.13 |
android/nowinandroid 구조 파헤치기 (0) | 2022.11.30 |