chore: dynamically calculate version code from version string

This commit is contained in:
Akash Yadav
2023-01-07 08:54:04 +05:30
parent 012ae9927a
commit 36595ed4cd
2 changed files with 13 additions and 5 deletions
@@ -40,9 +40,6 @@ object BuildConfig {
/** The target SDK version. */
const val targetSdk = 28
/** The version code. */
const val versionCode = 214
/** The source and target Java compatibility. */
val javaVersion = JavaVersion.VERSION_11
val javaVersionMajor = 11
+13 -2
View File
@@ -17,7 +17,6 @@
import com.android.build.gradle.BaseExtension
import com.itsaky.androidide.plugins.AndroidIDEPlugin
import com.mooltiverse.oss.nyx.state.State
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
@@ -29,6 +28,18 @@ plugins {
buildscript { dependencies { classpath("com.google.android.gms:oss-licenses-plugin:0.10.6") } }
val Project.projectVersionCode by lazy {
val version = rootProject.version.toString()
val regex = Regex("^v\\d+\\.?\\d+\\.?\\d+")
return@lazy regex.find(version)?.value?.substring(1)?.replace(".", "")?.toInt()?.also {
logger.warn("Version code is '$it' (from version ${rootProject.version}).")
}
?: throw IllegalStateException(
"Invalid version string '$version'. Version names must be SEMVER with 'v' prefix"
)
}
fun Project.configureBaseExtension() {
extensions.findByType(BaseExtension::class)?.run {
compileSdkVersion(BuildConfig.compileSdk)
@@ -37,7 +48,7 @@ fun Project.configureBaseExtension() {
defaultConfig {
minSdk = BuildConfig.minSdk
targetSdk = BuildConfig.targetSdk
versionCode = BuildConfig.versionCode
versionCode = projectVersionCode
versionName = rootProject.version.toString()
}