Add KMP convention plugin

pull/1323/head
lihenggui 2 years ago
parent d3314c2028
commit dcdc7f0c71

@ -110,5 +110,9 @@ gradlePlugin {
id = "nowinandroid.jvm.library"
implementationClass = "JvmLibraryConventionPlugin"
}
register("kmpLibrary") {
id = "nowinandroid.kmp.library"
implementationClass = "KmpLibraryConventionPlugin"
}
}
}

@ -0,0 +1,32 @@
/*
* Copyright 2024 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
*
* https://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 com.google.samples.apps.nowinandroid.configureKotlinMultiplatform
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* A plugin that applies the Kotlin Multiplatform plugin and configures it for the project.
* https://github.com/cashapp/sqldelight/blob/master/buildLogic/multiplatform-convention/src/main/kotlin/app/cash/sqldelight/multiplatform/MultiplatformConventions.kt
*/
class KmpLibraryConventionPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
plugins.apply("org.jetbrains.kotlin.multiplatform")
configureKotlinMultiplatform()
}
}
}

@ -0,0 +1,77 @@
/*
* Copyright 2024 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
*
* https://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.
*/
package com.google.samples.apps.nowinandroid
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.konan.target.HostManager
internal fun Project.configureKotlinMultiplatform() {
(project.kotlinExtension as KotlinMultiplatformExtension).apply {
jvm()
js {
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
compilations.configureEach {
kotlinOptions {
moduleKind = "umd"
}
}
}
// tier 1
linuxX64()
macosX64()
macosArm64()
iosSimulatorArm64()
iosX64()
// tier 2
linuxArm64()
watchosSimulatorArm64()
watchosX64()
watchosArm32()
watchosArm64()
tvosSimulatorArm64()
tvosX64()
tvosArm64()
iosArm64()
// tier 3
androidNativeArm32()
androidNativeArm64()
androidNativeX86()
androidNativeX64()
mingwX64()
watchosDeviceArm64()
// linking fails for the linux test build if not built on a linux host
// ensure the tests and linking for them is only done on linux hosts
project.tasks.named("linuxX64Test") { enabled = HostManager.hostIsLinux }
project.tasks.named("linkDebugTestLinuxX64") { enabled = HostManager.hostIsLinux }
project.tasks.named("mingwX64Test") { enabled = HostManager.hostIsMingw }
project.tasks.named("linkDebugTestMingwX64") { enabled = HostManager.hostIsMingw }
}
}

@ -202,3 +202,4 @@ nowinandroid-android-lint = { id = "nowinandroid.android.lint", version = "unspe
nowinandroid-android-room = { id = "nowinandroid.android.room", version = "unspecified" }
nowinandroid-android-test = { id = "nowinandroid.android.test", version = "unspecified" }
nowinandroid-jvm-library = { id = "nowinandroid.jvm.library", version = "unspecified" }
nowinandroid-kmp-library = { id = "nowinandroid.kmp.library", version = "unspecified" }

Loading…
Cancel
Save