Skip to content

Commit 86cd085

Browse files
committed
Feat: 앱 버전관리를 위한 컨벤션 플러그인 구현
- versionName을 major, minor, patch로 분리 - AndroidApplicationPlugin 및 AndroidLibraryPlugin에 configureAppVersion() 적용
1 parent eef3cb9 commit 86cd085

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

build-logic/convention/src/main/java/com/threegap/bitnagil/convention/AndroidApplicationPlugin.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.threegap.bitnagil.convention
22

33
import com.android.build.api.dsl.ApplicationExtension
4+
import com.threegap.bitnagil.convention.extension.configureAppVersion
45
import com.threegap.bitnagil.convention.extension.configureComposeAndroid
56
import com.threegap.bitnagil.convention.extension.configureKotlinAndroid
67
import org.gradle.api.Plugin
@@ -21,10 +22,10 @@ class AndroidApplicationPlugin : Plugin<Project> {
2122
extensions.configure<ApplicationExtension> {
2223
configureKotlinAndroid(this)
2324
configureComposeAndroid(this)
25+
configureAppVersion()
2426
with(defaultConfig) {
2527
targetSdk = libs.findVersion("targetSdk").get().requiredVersion.toInt()
2628
versionCode = libs.findVersion("versionCode").get().requiredVersion.toInt()
27-
versionName = libs.findVersion("versionName").get().requiredVersion
2829
}
2930
}
3031
}

build-logic/convention/src/main/java/com/threegap/bitnagil/convention/AndroidLibraryPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.threegap.bitnagil.convention
22

33
import com.android.build.gradle.LibraryExtension
4+
import com.threegap.bitnagil.convention.extension.configureAppVersion
45
import com.threegap.bitnagil.convention.extension.configureKotlinAndroid
56
import com.threegap.bitnagil.convention.extension.configureKotlinCoroutine
67
import org.gradle.api.Plugin
@@ -17,6 +18,7 @@ class AndroidLibraryPlugin : Plugin<Project> {
1718
extensions.configure<LibraryExtension> {
1819
configureKotlinAndroid(this)
1920
configureKotlinCoroutine(this)
21+
configureAppVersion()
2022
}
2123
}
2224
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.threegap.bitnagil.convention.extension
2+
3+
import com.android.build.api.dsl.ApplicationExtension
4+
import com.android.build.api.dsl.LibraryExtension
5+
import org.gradle.api.Project
6+
import org.gradle.api.artifacts.VersionCatalogsExtension
7+
import org.gradle.kotlin.dsl.findByType
8+
import org.gradle.kotlin.dsl.getByType
9+
10+
internal fun Project.configureAppVersion() {
11+
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
12+
val major = libs.findVersion("versionMajor").get().requiredVersion
13+
val minor = libs.findVersion("versionMinor").get().requiredVersion
14+
val patch = libs.findVersion("versionPatch").get().requiredVersion
15+
16+
extensions.findByType<ApplicationExtension>()?.let { appExtension ->
17+
appExtension.defaultConfig {
18+
versionName = "$major.$minor.$patch"
19+
buildConfigField("int", "VERSION_MAJOR", major)
20+
buildConfigField("int", "VERSION_MINOR", minor)
21+
buildConfigField("int", "VERSION_PATCH", patch)
22+
}
23+
}
24+
25+
extensions.findByType<LibraryExtension>()?.let { libExtension ->
26+
libExtension.apply {
27+
defaultConfig {
28+
buildConfigField("int", "VERSION_MAJOR", major)
29+
buildConfigField("int", "VERSION_MINOR", minor)
30+
buildConfigField("int", "VERSION_PATCH", patch)
31+
}
32+
buildFeatures {
33+
buildConfig = true
34+
}
35+
}
36+
}
37+
}

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ targetSdk = "35"
66

77
## App Versioning
88
versionCode = "4"
9-
versionName = "1.0.2"
9+
versionMajor = "1"
10+
versionMinor = "0"
11+
versionPatch = "2"
1012

1113
# Android Gradle Plugin
1214
androidGradlePlugin = "8.10.1"

0 commit comments

Comments
 (0)