blob: 535b1dcb10640c6dbd7691f0d0c0a42372b15f95 [file] [log] [blame]
/*
* Copyright 2021 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.Publish
import me.champeau.gradle.japicmp.JapicmpTask
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
buildscript {
dependencies {
classpath(libs.japicmpPluginz)
classpath(libs.atomicFuPluginz)
}
}
plugins {
id("AndroidXPlugin")
// multiplatform must be above java due to b/205844758
id("org.jetbrains.kotlin.multiplatform")
id("java") // https://github.com/gradle/gradle/issues/18622
id("me.champeau.gradle.japicmp")
}
// This should be true when building from GitHub, and false when building
// from AOSP. Use this to block out any features or code that we're not
// ready to build yet in AOSP
def boolProperty(name) {
return project.providers.gradleProperty(name).getOrNull()?.toBoolean()
}
def platformEnabled(platformString) {
return boolProperty("androidx.kmp.${platformString}.enabled")
}
def githubBuild = boolProperty('androidx.github.build') ?: false
def enableJs = platformEnabled('js') ?: githubBuild
def enableLinux = platformEnabled('linux') ?: githubBuild
def enableMac = platformEnabled('mac') ?: githubBuild
kotlin {
jvm {
withJava()
}
if (enableMac) {
macosX64 {
binaries {
framework {
baseName = "CollectionKMP"
}
}
}
}
if (enableJs) {
js {
nodejs()
}
}
if (enableLinux) {
linuxX64()
}
if (githubBuild) {
linuxX64()
mingwX64()
iosX64()
iosArm64()
iosArm32()
}
sourceSets {
all {
languageSettings {
progressiveMode = true
optIn("kotlin.ExperimentalStdlibApi") // STOPSHIP
}
}
commonMain {
dependencies {
api(libs.kotlinStdlibCommon)
}
}
commonTest {
dependencies {
implementation(libs.kotlinTestCommon)
implementation(libs.kotlinTestAnnotationsCommon)
}
}
if (githubBuild || enableMac || enableJs || enableLinux) {
nonJvmMain {
// Used for JS and all native targets.
dependencies {
api(libs.atomicFu)
}
}
}
if (enableMac) {
configure([macosX64Main]) {
dependsOn nonJvmMain
}
}
if (enableLinux) {
configure([linuxX64Main]) {
dependsOn nonJvmMain
}
}
if (githubBuild) {
configure([mingwX64Main, iosX64Main, iosArm32Main, iosArm64Main]) {
dependsOn nonJvmMain
}
}
if (githubBuild || enableMac || enableLinux) {
nativeTest // Used for all native targets.
}
if (enableMac) {
configure([macosX64Test]) {
dependsOn nativeTest
}
}
if (enableLinux) {
configure([linuxX64Test]) {
dependsOn nativeTest
}
}
if (githubBuild) {
configure([mingwX64Test, iosX64Test, iosArm32Test, iosArm64Test]) {
dependsOn nativeTest
}
}
if (enableJs) {
jsMain {
dependsOn nonJvmMain
dependencies {
api(libs.kotlinStdlibJs)
}
}
jsTest {
dependencies {
implementation(libs.kotlinTestJs)
}
}
}
jvmMain {
dependencies {
api(libs.kotlinStdlib)
api("androidx.annotation:annotation:1.1.0")
}
}
jvmTest {
dependencies {
implementation(libs.kotlinTestJunit)
implementation(libs.truth)
}
}
}
}
if (githubBuild || enableMac) {
// Workaround for https://youtrack.jetbrains.com/issue/KT-31603
sourceSets.test.java.srcDir('../../collection/collection/src/test/java')
}
def targetPlatformsList = ["jvm"]
if (enableJs) targetPlatformsList += "js"
androidx {
name = "Android Support Library collections"
publish = Publish.SNAPSHOT_AND_RELEASE
mavenGroup = LibraryGroups.COLLECTION2
inceptionYear = "2020"
description = "Standalone efficient collections."
legacyDisableKotlinStrictApiMode = true // TODO: Re-enable this!
publishPlatforms = targetPlatformsList
}
repositories {
mavenCentral()
}
configurations {
jvmApiBaseline
}
dependencies {
jvmApiBaseline('androidx.collection:collection:1.1.0') {
transitive = false
}
}
if (!githubBuild) {
tasks.withType(KotlinNativeCompile).configureEach {
kotlinOptions {
freeCompilerArgs += ["-Xoverride-konan-properties=dependenciesUrl=file:../../prebuilts/androidx/konan"]
}
}
}
def japicmpProvider = tasks.register("japicmp", JapicmpTask) { task ->
def jvmJar = tasks.getByName("jvmJar")
dependsOn(jvmJar)
task.oldClasspath = configurations.jvmApiBaseline
task.newClasspath = files(jvmJar.archivePath)
task.onlyBinaryIncompatibleModified = true
task.failOnModification = true
task.ignoreMissingClasses = true
task.includeSynthetic = true
task.txtOutputFile = file("$buildDir/reports/japi.txt")
}
// TODO(b/190741472): runErrorProne is currently broken.
runErrorProne.enabled = false