| /* |
| * Copyright (C) 2023 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 |
| * |
| * http://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 androidx.build.KmpPlatformsKt |
| import androidx.build.KotlinTarget |
| import org.apache.commons.io.FileUtils |
| import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
| import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink |
| import org.jetbrains.kotlin.konan.target.Family |
| |
| plugins { |
| id("AndroidXPlugin") |
| id("com.android.library") |
| id("com.google.devtools.ksp") |
| id("androidx.room") |
| } |
| |
| androidXMultiplatform { |
| android() |
| ios() |
| jvm() |
| linux() |
| mac() |
| sourceSets { |
| commonTest { |
| dependencies { |
| implementation(libs.kotlinStdlib) |
| implementation(project(":room:room-runtime")) |
| implementation(project(":room:room-testing")) |
| implementation(project(":room:room-paging")) |
| implementation(project(":sqlite:sqlite-bundled")) |
| implementation(project(":kruth:kruth")) |
| implementation(project(":paging:paging-common")) |
| implementation(libs.kotlinTest) |
| implementation(libs.kotlinCoroutinesTest) |
| } |
| } |
| androidInstrumentedTest { |
| dependsOn(commonTest) |
| dependencies { |
| implementation(libs.kotlinTestJunit) |
| implementation(libs.testRunner) |
| implementation(libs.testCore) |
| } |
| } |
| jvmTest { |
| dependsOn(commonTest) |
| dependencies { |
| implementation(libs.kotlinTestJunit) |
| } |
| } |
| nativeTest { |
| dependsOn(commonTest) |
| } |
| nonIosNativeTest { |
| dependsOn(nativeTest) |
| } |
| if (KmpPlatformsKt.enableMac(project)) { |
| iosTest { |
| dependsOn(nativeTest) |
| } |
| } |
| targets.configureEach { target -> |
| if (target.platformType == KotlinPlatformType.native) { |
| def test = target.compilations["test"] |
| if (target.konanTarget.family == Family.IOS) { |
| test.defaultSourceSet { |
| dependsOn(iosTest) |
| } |
| } else { |
| test.defaultSourceSet { |
| dependsOn(nonIosNativeTest) |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| // TODO(b/325111583): Create a helper function to configure KSP with KMP targets |
| dependencies { |
| def roomCompilerDependency = project(":room:room-compiler") |
| add("kspAndroidAndroidTest", roomCompilerDependency) // Android instrumentation test |
| add("kspAndroidTest", roomCompilerDependency) // Android unit test |
| add("kspJvmTest", roomCompilerDependency) |
| add("kspLinuxX64Test", roomCompilerDependency) |
| if (KmpPlatformsKt.enableMac(project)) { |
| add("kspIosSimulatorArm64Test", roomCompilerDependency) |
| add("kspIosX64Test", roomCompilerDependency) |
| add("kspMacosX64Test", roomCompilerDependency) |
| add("kspMacosArm64Test", roomCompilerDependency) |
| } |
| } |
| |
| android { |
| namespace = "androidx.room.integration.multiplatformtestapp" |
| } |
| |
| // Copy schema files to the iOS binary output test directory that will be part of the bundle's |
| // resources and read with NSBundle. This needs to be replaced with a more proper mechanism. |
| // TODO(b/317909626): Should be configured by Room Gradle Plugin |
| tasks.withType(KotlinNativeLink).configureEach { task -> |
| if (name.contains("linkDebugTestIos")) { |
| def inputSchemaDir = layout.projectDirectory.dir("schemas-ksp").getAsFile() |
| def outputSchemaDir = new File(task.destinationDirectory.getAsFile().get(), "/schemas-ksp") |
| task.doLast { |
| FileUtils.copyDirectory(inputSchemaDir, outputSchemaDir) |
| } |
| } |
| } |
| |
| room { |
| schemaDirectory( |
| provider { layout.projectDirectory.dir("schemas-ksp").getAsFile().getAbsolutePath() } |
| ) |
| } |
| |
| androidx { |
| kotlinTarget = KotlinTarget.KOTLIN_2_0 |
| } |
| |
| ksp { |
| useKsp2 = true |
| } |