|
| 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 | +} |
0 commit comments