| /* |
| * 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 com.android.build.gradle.internal.lint.AndroidLintAnalysisTask |
| import com.android.build.gradle.internal.lint.LintModelWriterTask |
| import com.google.devtools.ksp.gradle.KspAATask |
| 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 |
| import org.jetbrains.kotlin.konan.target.KonanTarget |
| |
| plugins { |
| id("AndroidXPlugin") |
| id("com.google.devtools.ksp") |
| id("androidx.room") |
| alias(libs.plugins.kotlinSerialization) |
| } |
| |
| androidXMultiplatform { |
| androidLibrary { |
| namespace = "androidx.room.integration.multiplatformtestapp" |
| androidResources.enable = true |
| } |
| ios() |
| jvm() |
| linux() |
| mac() |
| tvos() |
| watchos() |
| |
| 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) |
| implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.1") |
| } |
| } |
| // b/432783733: Test source set dedicating to room-paging since watchOS and tvOS are not |
| // supported targets. |
| pagingCommonTest { |
| dependsOn(commonTest) |
| } |
| androidInstrumentedTest { |
| dependsOn(commonTest) |
| dependsOn(pagingCommonTest) |
| dependencies { |
| implementation(libs.kotlinTestJunit) |
| implementation(libs.testRunner) |
| implementation(libs.testCore) |
| } |
| } |
| jvmTest { |
| dependsOn(commonTest) |
| dependsOn(pagingCommonTest) |
| dependencies { |
| implementation(libs.kotlinTestJunit) |
| } |
| } |
| nativeTest { |
| dependsOn(commonTest) |
| } |
| // Host OSes (Linux and Mac) |
| hostNativeTest { |
| dependsOn(nativeTest) |
| dependsOn(pagingCommonTest) |
| } |
| // iOS, watchOS and tvOS families, but not Mac OS |
| appleOsNativeTest { |
| dependsOn(nativeTest) |
| } |
| // iOS family |
| iosTest { |
| dependsOn(appleOsNativeTest) |
| dependsOn(pagingCommonTest) |
| } |
| targets.configureEach { target -> |
| if (target.platformType == KotlinPlatformType.native) { |
| target.compilations["test"].defaultSourceSet { |
| if (target.konanTarget.family in [Family.IOS, Family.WATCHOS, Family.TVOS]) { |
| if (target.konanTarget.family == Family.IOS) { |
| dependsOn(iosTest) |
| } else { |
| dependsOn(appleOsNativeTest) |
| } |
| } else { |
| dependsOn(hostNativeTest) |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| // TODO(b/325111583): Create a helper function to configure KSP with KMP targets |
| dependencies { |
| def roomCompilerDependency = project(":room:room-compiler") |
| add("kspAndroidInstrumentedTest", roomCompilerDependency) // Android instrumentation test |
| add("kspAndroidUnitTest", roomCompilerDependency) // Android unit test |
| add("kspJvmTest", roomCompilerDependency) |
| add("kspLinuxX64Test", roomCompilerDependency) |
| if (KmpPlatformsKt.enableMac(project)) { |
| add("kspIosArm64Test", roomCompilerDependency) |
| add("kspIosX64Test", roomCompilerDependency) |
| add("kspIosSimulatorArm64Test", roomCompilerDependency) |
| add("kspMacosX64Test", roomCompilerDependency) |
| add("kspMacosArm64Test", roomCompilerDependency) |
| add("kspTvosArm64Test", roomCompilerDependency) |
| add("kspTvosX64Test", roomCompilerDependency) |
| add("kspTvosSimulatorArm64Test", roomCompilerDependency) |
| add("kspWatchosArm64Test", roomCompilerDependency) |
| add("kspWatchosX64Test", roomCompilerDependency) |
| add("kspWatchosSimulatorArm64Test", roomCompilerDependency) |
| } |
| } |
| |
| // Copy schema files to the iOS / watchOS / tvOS 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. See https://youtrack.jetbrains.com/issue/KT-39194 |
| // TODO(b/317909626): Should be configured by Room Gradle Plugin |
| tasks.withType(KotlinNativeLink).configureEach { task -> |
| def isAppleOsTarget = task.target in [ |
| KonanTarget.IOS_ARM64, |
| KonanTarget.IOS_X64, |
| KonanTarget.IOS_SIMULATOR_ARM64, |
| KonanTarget.TVOS_ARM64, |
| KonanTarget.TVOS_X64, |
| KonanTarget.TVOS_SIMULATOR_ARM64, |
| KonanTarget.WATCHOS_ARM32, |
| KonanTarget.WATCHOS_ARM64, |
| KonanTarget.WATCHOS_X64, |
| KonanTarget.WATCHOS_SIMULATOR_ARM64, |
| KonanTarget.WATCHOS_DEVICE_ARM64 |
| ].collect { it.INSTANCE.name } |
| if (isAppleOsTarget) { |
| 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(layout.projectDirectory.dir("schemas-ksp").getAsFile().getAbsolutePath()) |
| } |
| |
| androidx { |
| kotlinTarget = KotlinTarget.KOTLIN_2_2 |
| } |
| |
| // TODO(https://github.com/google/ksp/issues/2250) Remove when KSP migrates to the new variants API |
| // Without this, dependency introduced between lintAnalyzeAndroidInstrumentedTest and kspAndroidInstrumentedTest |
| tasks.withType(AndroidLintAnalysisTask).configureEach { |
| mustRunAfter(tasks.withType(KspAATask)) |
| } |
| |
| // TODO(https://github.com/google/ksp/issues/2250) Remove when KSP migrates to the new variants API |
| // Without this, dependency introduced between lintAnalyzeAndroidInstrumentedTest and kspAndroidInstrumentedTest |
| tasks.withType(LintModelWriterTask).configureEach { |
| mustRunAfter(tasks.withType(KspAATask)) |
| } |
| |
| afterEvaluate { |
| // This project has commonTest/ sources, but none of these contain actual tests. This means that |
| // testAndroidHostTest will attempt to run as it has sources, but there will be no tests to run. |
| // Starting Gradle 9.0.0 this is an error, hence we disable this task here. |
| tasks.named("testAndroidHostTest") { it.enabled = false } |
| } |