/*
 * 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.LibraryType
import androidx.build.PlatformIdentifier
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
    id("AndroidXPlugin")
}

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

    defaultPlatform(PlatformIdentifier.JVM)

    sourceSets {
        commonMain {
            dependencies {
                api(libs.kotlinStdlib)
                api(libs.kotlinCoroutinesCore)
                api("androidx.annotation:annotation:1.8.1")
            }
        }

        jvmMain {
            dependsOn(commonMain)
            dependencies {
                api(libs.jspecify)
            }
        }

        jvmTest {
            dependsOn(commonTest)
            dependencies {
                implementation(libs.junit)
                implementation(libs.mockitoCore4)
            }
        }

        nonJvmCommonMain {
            dependsOn(commonMain)
            dependencies {
                implementation(libs.atomicFu)
            }
        }

        targets.configureEach { target ->
            if (target.platformType !in [KotlinPlatformType.jvm, KotlinPlatformType.common]) {
                target.compilations["main"].defaultSourceSet {
                    dependsOn(nonJvmCommonMain)
                }
            }
        }
    }
}

androidx {
    name = "Lifecycle-Common"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2017"
    description = "Android Lifecycle-Common"
}
