/*
 * Copyright (C) 2017 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.
 */

/**
 * This file was created using the `create_project.py` script located in the
 * `<AndroidX root>/development/project-creator` directory.
 *
 * Please use that script when creating a new project, rather than copying an existing project and
 * modifying its settings.
 */


import androidx.build.KotlinTarget
import androidx.build.PlatformIdentifier
import androidx.build.LibraryType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
    id("AndroidXPlugin")
    alias(libs.plugins.kotlinSerialization)
}

androidXMultiplatform {
    jvm() {
        withJava()
    }
    mac()
    linux()
    ios()

    defaultPlatform(PlatformIdentifier.JVM)

    sourceSets {
        commonMain {
            dependencies {
                api(libs.kotlinStdlib)
                implementation(project(":room:room-common"))
                implementation(libs.kotlinSerializationJson)
            }
        }
        commonTest {
            dependencies {
                implementation(project(":kruth:kruth"))
                implementation(libs.kotlinTest)
            }
        }
        jvmMain {
            dependsOn(commonMain)
        }
        jvmTest {
            dependsOn(commonTest)
            dependencies {
                implementation(libs.kotlinTestJunit)
            }
        }
        nativeMain {
            dependsOn(commonMain)
            dependencies {
                api(libs.okio)
                implementation(libs.kotlinSerializationJsonOkio)
            }
        }
        targets.configureEach { target ->
            if (target.platformType == KotlinPlatformType.native) {
                target.compilations["main"].defaultSourceSet {
                    dependsOn(nativeMain)
                }
            }
        }
    }
}

androidx {
    name = "Room Migration"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2017"
    description = "Android Room Migration"
    legacyDisableKotlinStrictApiMode = true
    kotlinTarget = KotlinTarget.KOTLIN_2_0
}
