diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 2c84a8003..a91e06232 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -114,5 +114,13 @@ gradlePlugin { id = "nowinandroid.kmp.library" implementationClass = "KmpLibraryConventionPlugin" } + register("kotlinInject") { + id = "nowinandroid.kmp.inject" + implementationClass = "KotlinInjectConventionPlugin" + } + register("sqldelight") { + id = "nowinandroid.sqldelight" + implementationClass = "SqlDelightConventionPlugin" + } } } diff --git a/build-logic/convention/src/main/kotlin/KotlinInjectConventionPlugin.kt b/build-logic/convention/src/main/kotlin/KotlinInjectConventionPlugin.kt new file mode 100644 index 000000000..61e491ff1 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/KotlinInjectConventionPlugin.kt @@ -0,0 +1,40 @@ +/* + * 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.libs +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.dependencies + +class KotlinInjectConventionPlugin: Plugin { + override fun apply(target: Project) { + with(target) { + with(pluginManager) { + apply("com.google.devtools.ksp") + } + dependencies { + add("kspCommonMainMetadata", libs.findLibrary("kotlin.inject.compiler.ksp").get()) + add("commonMainImplementation", libs.findLibrary("kotlin.inject.runtime").get()) + // KSP will eventually have better multiplatform support and we'll be able to simply have + // `ksp libs.kotlinInject.compiler` in the dependencies block of each source set + // https://github.com/google/ksp/pull/1021 + add("kspIosX64", libs.findLibrary("kotlin.inject.compiler.ksp").get()) + add("kspIosArm64", libs.findLibrary("kotlin.inject.compiler.ksp").get()) + add("kspIosSimulatorArm64", libs.findLibrary("kotlin.inject.compiler.ksp").get()) + } + } + } +} \ No newline at end of file diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts index 405649aa8..27cf0206b 100644 --- a/core/database/build.gradle.kts +++ b/core/database/build.gradle.kts @@ -16,8 +16,8 @@ plugins { alias(libs.plugins.nowinandroid.kmp.library) + alias(libs.plugins.nowinandroid.kotlin.inject) alias(libs.plugins.sqldelight.gradle.plugin) - alias(libs.plugins.ksp) } android { @@ -33,7 +33,6 @@ kotlin { commonMain.dependencies { api(projects.core.model) implementation(libs.kotlinx.datetime) - implementation(libs.kotlinInject.runtime) implementation(libs.sqldelight.coroutines.extensions) implementation(libs.sqldelight.primitive.adapters) } @@ -70,12 +69,3 @@ sqldelight { } } } - -dependencies { - // KSP will eventually have better multiplatform support and we'll be able to simply have - // `ksp libs.kotlinInject.compiler` in the dependencies block of each source set - // https://github.com/google/ksp/pull/1021 - add("kspIosX64", libs.kotlinInject.compiler) - add("kspIosArm64", libs.kotlinInject.compiler) - add("kspIosSimulatorArm64", libs.kotlinInject.compiler) -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7e6b1cc3d..053e1ab7f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -164,8 +164,8 @@ sqldelight-sqlite-driver = { group = "app.cash.sqldelight", name = "sqlite-drive sqldelight-webworker-driver = { group = "app.cash.sqldelight", name = "web-worker-driver", version.ref = "sqldelight" } sqldelight-coroutines-extensions = { group = "app.cash.sqldelight", name = "coroutines-extensions", version.ref = "sqldelight" } sqldelight-primitive-adapters = { group = "app.cash.sqldelight", name = "primitive-adapters", version.ref = "sqldelight" } -kotlinInject-compiler = { module = 'me.tatarka.inject:kotlin-inject-compiler-ksp', version.ref = 'kotlinInject' } -kotlinInject-runtime = { module = 'me.tatarka.inject:kotlin-inject-runtime', version.ref = 'kotlinInject' } +kotlin-inject-compiler-ksp = { group = "me.tatarka.inject", name = "kotlin-inject-compiler-ksp", version.ref = "kotlinInject" } +kotlin-inject-runtime = { group = "me.tatarka.inject", name = "kotlin-inject-runtime", version.ref = "kotlinInject" } # Dependencies of the included build-logic android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" } @@ -214,3 +214,6 @@ nowinandroid-android-room = { id = "nowinandroid.android.room", version = "unspe nowinandroid-android-test = { id = "nowinandroid.android.test", version = "unspecified" } nowinandroid-jvm-library = { id = "nowinandroid.jvm.library", version = "unspecified" } nowinandroid-kmp-library = { id = "nowinandroid.kmp.library", version = "unspecified" } +nowinandroid-kotlin-inject = { id = "nowinandroid.kmp.inject", version = "unspecified" } +nowinandroid-sqldelight = { id = "nowinandroid.sqldelight", version = "unspecified" } +