Skip to content

Commit 1bfa2e4

Browse files
committed
build(gradle): 优化版本代码和名称的环境变量读取逻辑
- 使用 takeIf 确保环境变量非空且非空白时才使用 - 保持默认值从 version.properties 文件中读取 - 提高版本配置的健壮性和可维护性
1 parent 2e9f74b commit 1bfa2e4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

build.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ val versionProps = Properties().apply {
1616
}
1717
}
1818

19-
// 优先使用环境变量,否则使用 version.properties 中的值
20-
val appVersionCode: Int = (System.getenv("APP_VERSION_CODE") ?: versionProps.getProperty("versionCode", "22")).toInt()
21-
val appVersionName: String = System.getenv("APP_VERSION_NAME") ?: versionProps.getProperty("versionName", "5.4.1")
19+
// 优先使用环境变量(非空时),否则使用 version.properties 中的值
20+
val appVersionCode: Int = (System.getenv("APP_VERSION_CODE")?.takeIf { it.isNotBlank() }
21+
?: versionProps.getProperty("versionCode", "22")).toInt()
22+
val appVersionName: String = System.getenv("APP_VERSION_NAME")?.takeIf { it.isNotBlank() }
23+
?: versionProps.getProperty("versionName", "5.4.1")
2224

2325
buildscript {
2426
repositories {

0 commit comments

Comments
 (0)