Skip to content

Commit 8fbb8d6

Browse files
authored
build: migrate to room gradle plugin (#1627)
* refactor: Versioning system moved to project-level build.gradle.kts file This commit updates the versioning logic. The `toVersionCode` function is also added to the `Version` class to calculate the version code based on the version components. - Added Room schemas folder creation when it doesn't exist - Updated deprecated code for the `clean` Gradle task * chore/refactor: add Room dedicated plugin This commit updates various changes, including: - Moved hardcoded version to version declaration (version.ref) for the androidx-compose-material3 dependency - Adding Room plugin to the project and configuring schema directory - Removing custom RoomSchemaArgProvider and using the built-in Room schema functionality - Updating versionCode to 20000 due to F-droid requirements * feat(build): enable incremental schema for room using ksp This commit enables incremental annotation processing for Room using ksp. - Added `room.incremental` argument to ksp configuration. - Note that this is not yet supported by the Room plugin.
1 parent 773ced4 commit 8fbb8d6

File tree

5 files changed

+79
-80
lines changed

5 files changed

+79
-80
lines changed

.idea/misc.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

+10-65
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,15 @@ plugins {
1010
alias(libs.plugins.kotlin.serialization)
1111
alias(libs.plugins.ksp)
1212
alias(libs.plugins.compose.compiler)
13+
alias(libs.plugins.room)
1314
}
1415

15-
sealed class Version(
16-
open val versionMajor: Int,
17-
val versionMinor: Int,
18-
val versionPatch: Int,
19-
val versionBuild: Int = 0
20-
) {
21-
abstract fun toVersionName(): String
22-
class Alpha(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
23-
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
24-
override fun toVersionName(): String =
25-
"${versionMajor}.${versionMinor}.${versionPatch}-alpha.$versionBuild"
26-
}
27-
28-
class Beta(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
29-
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
30-
override fun toVersionName(): String =
31-
"${versionMajor}.${versionMinor}.${versionPatch}-beta.$versionBuild"
32-
}
33-
34-
class Stable(versionMajor: Int, versionMinor: Int, versionPatch: Int) :
35-
Version(versionMajor, versionMinor, versionPatch) {
36-
override fun toVersionName(): String =
37-
"${versionMajor}.${versionMinor}.${versionPatch}"
38-
}
39-
40-
class ReleaseCandidate(
41-
versionMajor: Int,
42-
versionMinor: Int,
43-
versionPatch: Int,
44-
versionBuild: Int
45-
) :
46-
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
47-
override fun toVersionName(): String =
48-
"${versionMajor}.${versionMinor}.${versionPatch}-rc.$versionBuild"
49-
}
50-
}
51-
52-
val currentVersion: Version = Version.Alpha(
53-
versionMajor = 2,
54-
versionMinor = 0,
55-
versionPatch = 0,
56-
versionBuild = 2
57-
)
58-
5916
val keystorePropertiesFile: File = rootProject.file("keystore.properties")
6017

6118
val splitApks = !project.hasProperty("noSplits")
6219

6320
val abiFilterList = (properties["ABI_FILTERS"] as String).split(';')
6421

65-
6622
android {
6723
if (keystorePropertiesFile.exists()) {
6824
val keystoreProperties = Properties()
@@ -80,13 +36,11 @@ android {
8036

8137
compileSdk = 34
8238

83-
84-
8539
defaultConfig {
8640
applicationId = "com.junkfood.seal"
8741
minSdk = 24
8842
targetSdk = 34
89-
versionCode = 20000
43+
versionCode = 20000 // (rootProject.extra["versionCode"] as Int) -- Can't be used because of F-droid
9044

9145
if (splitApks) {
9246
splits {
@@ -99,24 +53,27 @@ android {
9953
}
10054
}
10155

102-
versionName = currentVersion.toVersionName().run {
56+
versionName = (rootProject.extra["versionName"] as String).run {
10357
if (!splitApks) "$this-(F-Droid)"
10458
else this
10559
}
10660
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
10761
vectorDrawables {
10862
useSupportLibrary = true
10963
}
110-
ksp {
111-
arg(RoomSchemaArgProvider(File(projectDir, "schemas")))
112-
arg("room.incremental", "true")
113-
}
64+
11465
if (!splitApks) {
11566
ndk {
11667
abiFilters.addAll(abiFilterList)
11768
}
11869
}
11970
}
71+
room {
72+
schemaDirectory("$projectDir/schemas")
73+
}
74+
ksp {
75+
arg("room.incremental", "true") //Still not supported by the Room plugin
76+
}
12077
val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 3, "x86_64" to 4)
12178

12279
androidComponents {
@@ -246,16 +203,4 @@ dependencies {
246203
androidTestImplementation(libs.androidx.test.ext)
247204
androidTestImplementation(libs.androidx.test.espresso.core)
248205
implementation(libs.androidx.compose.ui.tooling)
249-
250-
}
251-
252-
class RoomSchemaArgProvider(
253-
@get:InputDirectory
254-
@get:PathSensitive(PathSensitivity.RELATIVE)
255-
val schemaDir: File
256-
) : CommandLineArgumentProvider {
257-
258-
override fun asArguments(): Iterable<String> {
259-
return listOf("room.schemaLocation=${schemaDir.path}")
260-
}
261206
}

build.gradle.kts

+66-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,79 @@
1-
@file:Suppress("UnstableApiUsage")
1+
plugins {
2+
alias(libs.plugins.android.application) apply false
3+
alias(libs.plugins.android.library) apply false
4+
alias(libs.plugins.kotlin.android) apply false
5+
alias(libs.plugins.kotlin.serialization) apply false
6+
alias(libs.plugins.ksp) apply false
7+
alias(libs.plugins.compose.compiler) apply false
8+
alias(libs.plugins.room) apply false
9+
}
210

311
buildscript {
4-
512
repositories {
613
mavenCentral()
714
google()
815
}
916
}
1017

11-
@Suppress("DSL_SCOPE_VIOLATION")
12-
plugins {
13-
alias(libs.plugins.android.application) apply false
14-
alias(libs.plugins.android.library) apply false
15-
alias(libs.plugins.kotlin.android) apply false
16-
alias(libs.plugins.kotlin.serialization) apply false
17-
alias(libs.plugins.ksp) apply false
18-
alias(libs.plugins.compose.compiler) apply false
18+
sealed class Version(
19+
open val versionMajor: Int,
20+
val versionMinor: Int,
21+
val versionPatch: Int,
22+
val versionBuild: Int = 0
23+
) {
24+
abstract fun toVersionName(): String
25+
26+
fun toVersionCode(): Int {
27+
val minor = versionMinor.toString().padStart(2, '0')
28+
val patch = versionPatch.toString().padStart(2, '0')
29+
30+
// Combining the version components, ensuring the result is 5 digits
31+
// We suppose that the major version won't be greater than 9
32+
return "$versionMajor$minor$patch".toInt()
33+
}
34+
35+
36+
class Alpha(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
37+
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
38+
override fun toVersionName(): String =
39+
"${versionMajor}.${versionMinor}.${versionPatch}-alpha.$versionBuild"
40+
}
41+
42+
class Beta(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
43+
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
44+
override fun toVersionName(): String =
45+
"${versionMajor}.${versionMinor}.${versionPatch}-beta.$versionBuild"
46+
}
47+
48+
class Stable(versionMajor: Int, versionMinor: Int, versionPatch: Int) :
49+
Version(versionMajor, versionMinor, versionPatch) {
50+
override fun toVersionName(): String =
51+
"${versionMajor}.${versionMinor}.${versionPatch}"
52+
}
53+
54+
class ReleaseCandidate(
55+
versionMajor: Int,
56+
versionMinor: Int,
57+
versionPatch: Int,
58+
versionBuild: Int
59+
) :
60+
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
61+
override fun toVersionName(): String =
62+
"${versionMajor}.${versionMinor}.${versionPatch}-rc.$versionBuild"
63+
}
1964
}
2065

66+
val currentVersion: Version = Version.Alpha(
67+
versionMajor = 2,
68+
versionMinor = 0,
69+
versionPatch = 0,
70+
versionBuild = 2
71+
)
72+
73+
val versionCode by extra(currentVersion.toVersionCode())
74+
val versionName by extra(currentVersion.toVersionName())
75+
2176
tasks.register("clean", Delete::class) {
22-
delete(rootProject.buildDir)
77+
delete(rootProject.layout.buildDirectory)
2378
}
2479

color/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ dependencies {
3737
api(libs.androidx.core.ktx)
3838
api(libs.androidx.compose.foundation)
3939
api(libs.androidx.compose.material3)
40-
4140
}

gradle/libs.versions.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ androidxSplashscreen = "1.0.1"
1111
androidxLifecycle = "2.8.4"
1212
androidxNavigation = "2.7.7"
1313
androidxFoundation = "1.6.0-beta03"
14-
androidxComposeMaterial3 = "1.2.0-beta01"
14+
androidxComposeMaterial3 = "1.3.0-alpha06"
1515
androidxComposeAnimation = "1.5.0-beta01"
1616

1717
androidxEspresso = "3.5.0"
@@ -62,7 +62,7 @@ androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
6262

6363
androidx-compose-material = { group = "androidx.compose.material", name = "material" }
6464

65-
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version = "1.3.0-alpha06" }
65+
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidxComposeMaterial3" }
6666
androidx-compose-material3-windowSizeClass = { group = "androidx.compose.material3", name = "material3-window-size-class" }
6767

6868
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
@@ -110,6 +110,7 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi
110110
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
111111
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
112112
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
113+
room = { id = "androidx.room", version.ref = "room" }
113114

114115
[bundles]
115116
accompanist = [

0 commit comments

Comments
 (0)