blob: fa9b24f51d90a8dfc6c7fd3ea1b2d6a535ceea70 [file] [log] [blame]
/*
* Copyright 2018 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.Publish
import androidx.build.LibraryType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.konan.target.Family
plugins {
id("AndroidXPlugin")
}
def enableNative = KmpPlatformsKt.enableNative(project)
androidXMultiplatform {
jvm {
withJava()
}
mac()
linux()
ios()
sourceSets {
commonMain {
dependencies {
api(libs.kotlinStdlib)
}
}
commonTest {
dependencies {
implementation(libs.kotlinTest)
implementation(libs.kotlinTestAnnotationsCommon)
implementation(libs.kotlinCoroutinesCore)
}
}
if (enableNative) {
nativeMain {
dependsOn commonMain
}
nativeTest {
dependsOn commonTest
}
darwinMain {
dependsOn(nativeMain)
}
linuxMain {
dependsOn(nativeMain)
}
}
targets.all { target ->
if (target.platformType == KotlinPlatformType.native) {
target.compilations["main"].defaultSourceSet {
if (target.konanTarget.family == Family.OSX ||
target.konanTarget.family == Family.IOS) {
dependsOn(darwinMain)
} else if (target.konanTarget.family == Family.LINUX) {
dependsOn(linuxMain)
} else {
throw new GradleException("unknown native target ${target}")
}
}
target.compilations["test"].defaultSourceSet {
dependsOn(nativeTest)
}
}
}
// Workaround for https://youtrack.jetbrains.com/issue/KT-51763
// Make sure commonization runs before any compilation task.
tasks.withType(KotlinNativeCompile).configureEach {
it.dependsOn(tasks.named("commonize"))
}
jvmMain {
dependencies {
api("androidx.annotation:annotation:1.3.0")
}
}
jvmTest {
dependencies {
implementation(libs.kotlinTestJunit)
implementation(libs.truth)
implementation(project(":internal-testutils-truth"))
}
}
all {
languageSettings.optIn("kotlin.RequiresOptIn")
languageSettings.optIn("kotlin.contracts.ExperimentalContracts")
}
}
}
dependencies {
// Required for users who only depend on this artifact, but pull an older version of
// collection-ktx transitively, which would lead to duplicate definition since the -ktx
// extensions were moved into the main artifact.
constraints {
jvmImplementation("androidx.collection:collection-ktx:1.3.0-alpha01")
}
}
androidx {
name = "Android Support Library collections"
type = LibraryType.KMP_LIBRARY
mavenGroup = LibraryGroups.COLLECTION
inceptionYear = "2018"
description = "Standalone efficient collections."
}
kotlin.targets.withType(KotlinNativeTarget.class) {
binaries.all {
binaryOptions["memoryModel"] = "experimental"
}
}