Add sqldelight support and move source to the commonMain folder

pull/1323/head
lihenggui 2 years ago
parent 429dabc14b
commit bdf201762e

@ -114,5 +114,9 @@ gradlePlugin {
id = "nowinandroid.kmp.library"
implementationClass = "KmpLibraryConventionPlugin"
}
register("kmpAndroidLibrary") {
id = "nowinandroid.kmp.android.library"
implementationClass = "KmpAndroidLibraryConventionPlugin"
}
}
}

@ -1,27 +0,0 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.google.samples.apps.nowinandroid.configureAndroidKotlinMultiplatform
import org.gradle.api.Plugin
import org.gradle.api.Project
class KmpAndroidLibraryConventionPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
plugins.apply("org.jetbrains.kotlin.multiplatform")
configureAndroidKotlinMultiplatform()
}
}
}

@ -14,15 +14,30 @@
* limitations under the License.
*/
import com.android.build.gradle.LibraryExtension
import com.google.samples.apps.nowinandroid.configureFlavors
import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
import com.google.samples.apps.nowinandroid.configureKotlinMultiplatform
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
class KmpLibraryConventionPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
plugins.apply("com.android.library")
plugins.apply("org.jetbrains.kotlin.multiplatform")
configureKotlinMultiplatform()
extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 34
configureFlavors(this)
configureGradleManagedDevices(this)
// The resource prefix is derived from the module name,
// so resources inside ":core:module1" must be prefixed with "core_module1_"
resourcePrefix = path.split("""\W""".toRegex()).drop(1).distinct().joinToString(separator = "_").lowercase() + "_"
}
}
}
}

@ -0,0 +1,39 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.gradle.LibraryExtension
import com.google.samples.apps.nowinandroid.configureFlavors
import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
import com.google.samples.apps.nowinandroid.configurePrintApksTask
import com.google.samples.apps.nowinandroid.disableUnnecessaryAndroidTests
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.kotlin
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
class SqlDelightConventionPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("app.cash.sqldelight")
extensions.configure<KotlinMultiplatformExtension> {
}
}
}
}

@ -28,6 +28,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
internal fun Project.configureKotlinMultiplatform() {
extensions.configure<KotlinMultiplatformExtension> {
jvm()
androidTarget()
js {
browser {
@ -83,10 +84,3 @@ internal fun Project.configureKotlinMultiplatform() {
}
}
}
internal fun Project.configureAndroidKotlinMultiplatform() {
extensions.configure<KotlinMultiplatformExtension> {
androidTarget()
}
configureKotlinMultiplatform()
}

@ -48,4 +48,5 @@ plugins {
alias(libs.plugins.room) apply false
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.sqldelight.gradle.plugin) apply false
}

@ -1,5 +1,5 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,10 +15,8 @@
*/
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.library.jacoco)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.nowinandroid.android.room)
alias(libs.plugins.nowinandroid.kmp.library)
alias(libs.plugins.sqldelight.gradle.plugin)
}
android {
@ -29,10 +27,33 @@ android {
namespace = "com.google.samples.apps.nowinandroid.core.database"
}
dependencies {
api(projects.core.model)
implementation(libs.kotlinx.datetime)
androidTestImplementation(projects.core.testing)
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(projects.core.model)
implementation(libs.kotlinx.datetime)
}
}
val androidMain by getting {
dependencies {
implementation(libs.sqldelight.android.driver)
}
}
val nativeMain by getting {
dependencies {
implementation(libs.sqldelight.native.driver)
}
}
val jvmMain by getting {
dependencies {
implementation(libs.sqldelight.sqlite.driver)
}
}
val commonTest by getting {
dependencies {
implementation(libs.kotlin.test)
}
}
}
}

@ -18,6 +18,10 @@ plugins {
alias(libs.plugins.nowinandroid.kmp.library)
}
android {
namespace = "com.google.samples.apps.nowinandroid.core.model"
}
kotlin {
sourceSets {
commonMain.dependencies {

@ -70,6 +70,7 @@ androidx-test-junit = "1.1.5"
compose = "1.6.0"
compose-plugin = "1.6.0-alpha01"
junit = "4.13.2"
sqldelight = "2.0.1"
[libraries]
accompanist-permissions = { group = "com.google.accompanist", name = "accompanist-permissions", version.ref = "accompanist" }
@ -156,6 +157,9 @@ androidx-material = { group = "com.google.android.material", name = "material",
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
sqldelight-android-driver = { group = "app.cash.sqldelight", name = "android-driver", version.ref = "sqldelight" }
sqldelight-native-driver = { group = "app.cash.sqldelight", name = "native-driver", version.ref = "sqldelight" }
sqldelight-sqlite-driver = { group = "app.cash.sqldelight", name = "sqlite-driver", version.ref = "sqldelight" }
# Dependencies of the included build-logic
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
@ -186,6 +190,7 @@ room = { id = "androidx.room", version.ref = "room" }
secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
sqldelight-gradle-plugin = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
# Plugins defined by this project
nowinandroid-android-application = { id = "nowinandroid.android.application", version = "unspecified" }

Loading…
Cancel
Save