Skip to content

Commit 59302bd

Browse files
committed
build: refactor versioning system and introduce BuildConfig
- Relocate version properties file to project root - Transition versioning to semantic MAJOR, MINOR, and PATCH components - Introduce automated BuildConfig generation for JVM - Integrate generated VERSION_NAME into crash reporting configuration - Update build workflow to parse semantic version components - Configure Gradle tasks to handle generated source directories and dependencies
1 parent 2c390ba commit 59302bd

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

.github/workflows/build-desktop.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ jobs:
5151
env:
5252
SENTRY_DNS: ${{ secrets.SENTRY_DNS }}
5353
run: |
54-
VERSION=${{ github.ref_name }}
54+
MAJOR=$(grep "MAJOR=" version.properties | cut -d'=' -f2)
55+
MINOR=$(grep "MINOR=" version.properties | cut -d'=' -f2)
56+
PATCH=$(grep "PATCH=" version.properties | cut -d'=' -f2)
57+
VERSION="$MAJOR.$MINOR.$PATCH"
5558
echo "is_release=true" > composeApp/src/jvmMain/resources/props.properties
5659
echo "sentry_dns=$SENTRY_DNS" >> composeApp/src/jvmMain/resources/props.properties
5760
echo "version=$VERSION" >> composeApp/src/jvmMain/resources/props.properties

composeApp/build.gradle.kts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ group = "com.meet"
1414
val appVersionName: () -> String by extra
1515
val appVersionCode: () -> Int by extra
1616

17+
// Generate BuildConfig for JVM (Configuration Cache Compatible)
18+
val generateJvmBuildConfig = tasks.register("generateJvmBuildConfig") {
19+
val outputDir = layout.buildDirectory.dir("generated/buildconfig/jvm")
20+
outputs.dir(outputDir)
21+
22+
doLast {
23+
val file = outputDir.get().asFile.resolve("com/meet/dev/analyzer/BuildConfig.kt")
24+
file.parentFile.mkdirs()
25+
file.writeText(
26+
"""
27+
package com.meet.dev.analyzer
28+
29+
object BuildConfig {
30+
const val VERSION_NAME = "${appVersionName()}"
31+
}
32+
""".trimIndent()
33+
)
34+
}
35+
}
36+
1737
java {
1838
toolchain {
1939
vendor = JvmVendorSpec.JETBRAINS
@@ -89,6 +109,9 @@ kotlin {
89109
commonTest.dependencies {
90110
implementation(libs.kotlin.test)
91111
}
112+
jvmMain {
113+
kotlin.srcDir(layout.buildDirectory.dir("generated/buildconfig/jvm"))
114+
}
92115
jvmMain.dependencies {
93116
// Compose Desktop
94117
implementation(compose.desktop.currentOs) // Platform-specific desktop support
@@ -99,6 +122,16 @@ kotlin {
99122
}
100123
}
101124

125+
afterEvaluate {
126+
tasks.matching { it.name.contains("kspKotlinJvm") || it.name == "compileKotlinJvm" }
127+
.configureEach {
128+
dependsOn(generateJvmBuildConfig)
129+
}
130+
}
131+
132+
tasks.named("compileKotlinJvm") {
133+
dependsOn(generateJvmBuildConfig)
134+
}
102135

103136
compose {
104137
resources {

composeApp/src/jvmMain/kotlin/com/meet/dev/analyzer/utility/crash_report/CustomProperties.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.meet.dev.analyzer.utility.crash_report
22

3+
import com.meet.dev.analyzer.BuildConfig
34
import com.meet.dev.analyzer.utility.platform.AppEnvironment
45
import com.meet.dev.analyzer.utility.platform.DesktopConfig
56
import java.io.InputStream
@@ -17,7 +18,7 @@ object CustomProperties {
1718

1819
fun createAppConfig(properties: Properties): DesktopConfig {
1920
val sentryDns = properties["sentry_dns"]?.toString()
20-
val version = properties["version"]?.toString()
21+
val version = BuildConfig.VERSION_NAME
2122
val isRelease = properties["is_release"]?.toString()?.toBooleanStrictOrNull() ?: false
2223

2324
val appEnvironment = if (isRelease) AppEnvironment.Release else AppEnvironment.Debug

version.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MAJOR=1
2+
MINOR=2
3+
PATCH=1

versioning.gradle.kts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import java.util.Date
33
import java.util.Properties
44

55
val versionProps = Properties()
6-
val versionPropertiesFile = rootProject.file("composeApp/src/jvmMain/resources/props.properties")
6+
val versionPropertiesFile = rootProject.file("version.properties")
77
if (versionPropertiesFile.exists()) {
88
versionPropertiesFile.inputStream().use { versionProps.load(it) }
99
} else {
10-
throw GradleException("Root project version.properties not found! Please ensure it exists with the version number.")
10+
throw GradleException("Root project version.properties not found! Please ensure it exists with MAJOR, MINOR, PATCH values.")
1111
}
1212
fun getCurrentTimestamp(): String {
1313
val sdf = SimpleDateFormat("yyyyMMddHHmm")
@@ -24,8 +24,12 @@ fun appVersionCode(): Int {
2424
}
2525
}
2626

27+
val appMajorVersion = versionProps.getProperty("MAJOR").toInt()
28+
val appMinorVersion = versionProps.getProperty("MINOR").toInt()
29+
val appPatchVersion = versionProps.getProperty("PATCH").toInt()
30+
2731
fun appVersionName(): String {
28-
return versionProps.getProperty("version")
32+
return "${appMajorVersion}.${appMinorVersion}.${appPatchVersion}"
2933
}
3034

3135
project.extra.set("appVersionCode", ::appVersionCode)

0 commit comments

Comments
 (0)