Skip to content

Commit abcc4bd

Browse files
authored
chore: Update Gradle config for KMP (#77)
1 parent 99740aa commit abcc4bd

11 files changed

Lines changed: 61 additions & 126 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ jobs:
128128
force-avd-creation: false
129129
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
130130
disable-animations: true
131-
script: ./gradlew :generic-datastore:connectedDebugAndroidTest
131+
script: ./gradlew :generic-datastore:connectedAndroidDeviceTest

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88
alias(libs.plugins.compose.compiler) apply false
99
alias(libs.plugins.kotlin.multiplatform) apply false
1010
alias(libs.plugins.spotless) apply false
11+
alias(libs.plugins.vanniktech.maven.publish) apply false
1112
}
1213

1314
version = "1.0.0"

generic-datastore-compose/build.gradle.kts

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1+
import com.android.build.api.dsl.androidLibrary
2+
13
plugins {
24
alias(libs.plugins.kotlin.multiplatform)
3-
`maven-publish`
4-
id("com.android.library")
5+
alias(libs.plugins.vanniktech.maven.publish)
6+
alias(libs.plugins.android.library)
57
alias(libs.plugins.compose.compiler)
68
}
79

810
kotlin {
9-
androidTarget {
10-
publishLibraryVariants("release")
11+
androidLibrary {
12+
namespace = "io.github.arthurkun.generic.datastore.compose"
13+
compileSdk = libs.versions.compile.sdk.get().toInt()
14+
minSdk = libs.versions.min.sdk.get().toInt()
15+
16+
optimization {
17+
consumerKeepRules.file("consumer-rules.pro")
18+
}
19+
20+
withDeviceTest {
21+
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
22+
}
1123
}
1224

1325
jvm("desktop") {
1426
testRuns["test"].executionTask.configure {
1527
useJUnitPlatform()
1628
}
1729
}
18-
// listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach { target ->
19-
// target.binaries.framework {
20-
// baseName = project.name
21-
// isStatic = true
22-
// }
23-
// }
2430

2531
sourceSets {
26-
val commonMain by getting {
27-
dependencies {
28-
api(project(":generic-datastore")) // Core library dependency
29-
implementation(libs.bundles.library.compose)
30-
}
31-
}
32-
val commonTest by getting {
33-
dependencies {
34-
implementation(libs.kotlin.test)
35-
implementation(libs.junit4)
36-
implementation(libs.coroutines.test)
37-
}
32+
commonMain.dependencies {
33+
api(project(":generic-datastore")) // Core library dependency
34+
implementation(libs.bundles.library.compose)
3835
}
3936

40-
val androidMain by getting
41-
val desktopMain by getting
37+
commonTest.dependencies {
38+
implementation(libs.kotlin.test)
39+
implementation(libs.junit4)
40+
implementation(libs.coroutines.test)
41+
}
4242
}
4343

4444
compilerOptions {
@@ -48,37 +48,6 @@ kotlin {
4848
}
4949
}
5050

51-
android {
52-
namespace = "io.github.arthurkun.generic.datastore.compose"
53-
compileSdk = libs.versions.compile.sdk.get().toInt()
54-
defaultConfig {
55-
minSdk = libs.versions.min.sdk.get().toInt()
56-
consumerProguardFiles("consumer-rules.pro") // Restored for consumers of the library
57-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
58-
}
59-
buildTypes {
60-
release {
61-
isMinifyEnabled = false
62-
proguardFiles(
63-
getDefaultProguardFile("proguard-android-optimize.txt"),
64-
"proguard-rules.pro",
65-
)
66-
}
67-
}
68-
sourceSets {
69-
getByName("androidTest") {
70-
// Android test source set
71-
java.srcDir("src/androidInstrumentedTest/kotlin")
72-
}
73-
}
74-
publishing {
75-
singleVariant("release") {
76-
withSourcesJar()
77-
withJavadocJar()
78-
}
79-
}
80-
}
81-
8251
publishing {
8352
publications {
8453
withType<MavenPublication> {

generic-datastore/build.gradle.kts

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
1+
import com.android.build.api.dsl.androidLibrary
2+
13
plugins {
24
alias(libs.plugins.kotlin.multiplatform)
3-
`maven-publish`
4-
id("com.android.library")
5+
alias(libs.plugins.vanniktech.maven.publish)
6+
alias(libs.plugins.android.library)
57
}
68

79
kotlin {
8-
androidTarget {
9-
publishLibraryVariants("release")
10+
androidLibrary {
11+
namespace = "io.github.arthurkun.generic.datastore"
12+
compileSdk = libs.versions.compile.sdk.get().toInt()
13+
minSdk = libs.versions.min.sdk.get().toInt()
14+
15+
withJava()
16+
17+
optimization {
18+
consumerKeepRules.file("consumer-rules.pro")
19+
}
20+
21+
withDeviceTest {
22+
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
23+
}
1024
}
1125

1226
jvm("desktop") {
1327
testRuns["test"].executionTask.configure {
1428
useJUnitPlatform()
1529
}
1630
}
17-
// listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach { target ->
18-
// target.binaries.framework {
19-
// baseName = project.name
20-
// isStatic = true
21-
// }
22-
// }
2331

2432
sourceSets {
25-
val commonMain by getting {
26-
dependencies {
27-
implementation(libs.datastore.preferences.core)
28-
implementation(libs.kotlinx.serialization.json)
29-
}
33+
commonMain.dependencies {
34+
implementation(libs.datastore.preferences.core)
35+
implementation(libs.kotlinx.serialization.json)
3036
}
31-
val commonTest by getting {
32-
dependencies {
33-
implementation(libs.kotlin.test)
34-
implementation(libs.junit4)
35-
implementation(libs.coroutines.test)
36-
}
37+
38+
commonTest.dependencies {
39+
implementation(libs.kotlin.test)
40+
implementation(libs.junit4)
41+
implementation(libs.coroutines.test)
3742
}
3843

39-
val androidMain by getting
40-
val androidInstrumentedTest by getting {
44+
getByName("androidDeviceTest") {
4145
dependencies {
4246
implementation(libs.datastore.preferences)
4347
implementation(libs.kotlin.test)
@@ -47,8 +51,6 @@ kotlin {
4751
implementation(libs.androidx.test.espresso)
4852
}
4953
}
50-
51-
val desktopMain by getting
5254
val desktopTest by getting {
5355
dependencies {
5456
// JVM-specific test dependencies
@@ -64,37 +66,6 @@ kotlin {
6466
}
6567
}
6668

67-
android {
68-
namespace = "io.github.arthurkun.generic.datastore"
69-
compileSdk = libs.versions.compile.sdk.get().toInt()
70-
defaultConfig {
71-
minSdk = libs.versions.min.sdk.get().toInt()
72-
consumerProguardFiles("consumer-rules.pro") // Restored for consumers of the library
73-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
74-
}
75-
buildTypes {
76-
release {
77-
isMinifyEnabled = false
78-
proguardFiles(
79-
getDefaultProguardFile("proguard-android-optimize.txt"),
80-
"proguard-rules.pro",
81-
)
82-
}
83-
}
84-
sourceSets {
85-
getByName("androidTest") {
86-
// Android test source set
87-
java.srcDir("src/androidInstrumentedTest/kotlin")
88-
}
89-
}
90-
publishing {
91-
singleVariant("release") {
92-
withSourcesJar()
93-
withJavadocJar()
94-
}
95-
}
96-
}
97-
9869
publishing {
9970
publications {
10071
withType<MavenPublication> {

generic-datastore/src/androidInstrumentedTest/kotlin/io/github/arthurkun/generic/datastore/AndroidDatastoreBlockingInstrumentedTest.kt renamed to generic-datastore/src/androidDeviceTest/kotlin/io/github/arthurkun/generic/datastore/AndroidDatastoreBlockingInstrumentedTest.kt

File renamed without changes.

generic-datastore/src/androidInstrumentedTest/kotlin/io/github/arthurkun/generic/datastore/AndroidDatastoreInstrumentedTest.kt renamed to generic-datastore/src/androidDeviceTest/kotlin/io/github/arthurkun/generic/datastore/AndroidDatastoreInstrumentedTest.kt

File renamed without changes.

generic-datastore/src/androidInstrumentedTest/kotlin/io/github/arthurkun/generic/datastore/ExampleInstrumentedTest.kt renamed to generic-datastore/src/androidDeviceTest/kotlin/io/github/arthurkun/generic/datastore/ExampleInstrumentedTest.kt

File renamed without changes.

generic-datastore/src/commonMain/kotlin/io/github/arthurkun/generic/datastore/EnumPreference.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ inline fun <reified T : Enum<T>> PreferenceDatastore.enum(
2323
deserializer = {
2424
try {
2525
enumValueOf(it)
26-
} catch (e: IllegalArgumentException) {
27-
println(
28-
"$TAG: Enum value $it not found for key $key, " +
29-
"returning default value $defaultValue ${e.message}",
30-
)
26+
} catch (_: IllegalArgumentException) {
3127
defaultValue
3228
}
3329
},

generic-datastore/src/commonMain/kotlin/io/github/arthurkun/generic/datastore/MappedPreference.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ internal class MappedPrefs<T, R>(
102102
private fun convertFallback(value: T): R {
103103
return try {
104104
convert(value)
105-
} catch (e: Exception) {
106-
println("$TAG: Error converting preference value $e")
105+
} catch (_: Exception) {
107106
defaultValue
108107
}
109108
}
@@ -119,8 +118,7 @@ internal class MappedPrefs<T, R>(
119118
private fun reverseFallback(value: R): T {
120119
return try {
121120
reverse(value)
122-
} catch (e: Exception) {
123-
println("$TAG: Error converting preference value $e")
121+
} catch (_: Exception) {
124122
prefs.defaultValue
125123
}
126124
}

generic-datastore/src/commonMain/kotlin/io/github/arthurkun/generic/datastore/Tag.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)