[build] Do not apply Android-relevant plugins if Android target is not enabled

This commit is contained in:
Him188 2023-05-01 10:56:16 +01:00
parent 438b58c717
commit 2ef89d2b3f
7 changed files with 16 additions and 31 deletions

View File

@ -43,6 +43,7 @@ plugins {
id("com.gradle.plugin-publish") version "1.1.0" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version Versions.binaryValidator apply false
id("com.android.library") apply false
id("de.mannodermaus.android-junit5") version "1.8.2.1" apply false
}
osDetector = osdetector

View File

@ -34,7 +34,7 @@ val ENABLE_ANDROID_INSTRUMENTED_TESTS by projectLazy {
val Project.usingAndroidInstrumentedTests
get() = ENABLE_ANDROID_INSTRUMENTED_TESTS && isAndroidSdkAvailable
fun Project.configureAndroidTarget() {
fun Project.configureAndroidTarget(androidNamespace: String) {
if (ENABLE_ANDROID_INSTRUMENTED_TESTS && !isAndroidSdkAvailable) {
if (!ProjectAndroidSdkAvailability.tryFixAndroidSdk(this)) {
printAndroidNotInstalled()
@ -43,7 +43,7 @@ fun Project.configureAndroidTarget() {
extensions.getByType(KotlinMultiplatformExtension::class.java).apply {
if (project.usingAndroidInstrumentedTests) {
configureAndroidTargetWithSdk()
configureAndroidTargetWithSdk(androidNamespace)
} else {
configureAndroidTargetWithJvm()
}
@ -82,7 +82,12 @@ private fun Project.configureAndroidTargetWithJvm() {
private const val PROP_MIRAI_ANDROID_SDK_KIND = "mirai.android.sdk.kind"
@Suppress("UnstableApiUsage")
private fun Project.configureAndroidTargetWithSdk() {
private fun Project.configureAndroidTargetWithSdk(androidNamespace: String) {
apply(plugin = "com.android.library")
apply(plugin = "de.mannodermaus.android-junit5")
extensions.getByType(LibraryExtension::class).apply {
namespace = androidNamespace
}
extensions.getByType(KotlinMultiplatformExtension::class.java).apply {
android {
if (IDEA_ACTIVE) {

View File

@ -164,7 +164,7 @@ const val JVM_TOOLCHAIN_VERSION = 8
*
* @see configureNativeTargetsHierarchical
*/
fun Project.configureJvmTargetsHierarchical() {
fun Project.configureJvmTargetsHierarchical(androidNamespace: String) {
extensions.getByType(KotlinMultiplatformExtension::class.java).apply {
val commonMain by sourceSets.getting
val commonTest by sourceSets.getting
@ -200,7 +200,7 @@ fun Project.configureJvmTargetsHierarchical() {
}
if (isTargetEnabled("android")) {
configureAndroidTarget()
configureAndroidTarget(androidNamespace)
}
if (isTargetEnabled("jvm")) {

View File

@ -12,7 +12,6 @@
plugins {
kotlin("multiplatform")
`maven-publish`
id("com.android.library")
}
version = Versions.console
@ -22,12 +21,8 @@ kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureJvmTargetsHierarchical("net.mamoe.mirai.compiler.annotations")
configureNativeTargetsHierarchical(project)
}
configureMppPublishing()
android {
namespace = "net.mamoe.mirai.compiler.annotations"
}

View File

@ -12,7 +12,6 @@ import BinaryCompatibilityConfigurator.configureBinaryValidators
import shadow.relocateCompileOnly
plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
@ -31,7 +30,7 @@ kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureJvmTargetsHierarchical("net.mamoe.mirai")
configureNativeTargetsHierarchical(project)
@ -125,7 +124,3 @@ configureBinaryValidators(setOf("jvm", "android").filterTargets())
// licenseFromGitHubProject("AGPLv3", "dev")
// publishPlatformArtifactsInRootModule = "jvm"
//}
android {
namespace = "net.mamoe.mirai"
}

View File

@ -12,7 +12,6 @@
import shadow.relocateImplementation
plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
@ -28,7 +27,7 @@ kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureJvmTargetsHierarchical("net.mamoe.mirai.utils")
configureNativeTargetsHierarchical(project)
sourceSets {
@ -108,8 +107,4 @@ configureMppPublishing()
// developer("Mamoe Technologies", email = "support@mamoe.net", url = "https://github.com/mamoe")
// licenseFromGitHubProject("AGPLv3", "dev")
// publishPlatformArtifactsInRootModule = "jvm"
//}
android {
namespace = "net.mamoe.mirai.utils"
}
//}

View File

@ -16,7 +16,6 @@ import shadow.relocateCompileOnly
import shadow.relocateImplementation
plugins {
id("com.android.library")
kotlin("multiplatform")
id("kotlinx-atomicfu")
kotlin("plugin.serialization")
@ -24,7 +23,6 @@ plugins {
id("me.him188.kotlin-dynamic-delegation")
// id("me.him188.maven-central-publish")
`maven-publish`
id("de.mannodermaus.android-junit5") version "1.8.2.1"
}
description = "Mirai Protocol implementation for QQ Android"
@ -33,7 +31,7 @@ kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureJvmTargetsHierarchical("net.mamoe.mirai.internal")
configureNativeTargetsHierarchical(project)
configureNativeTargetBinaries(project) // register native binaries for mirai-core only
@ -270,7 +268,3 @@ configureBinaryValidators(setOf("jvm", "android").filterTargets())
// licenseFromGitHubProject("AGPLv3", "dev")
// publishPlatformArtifactsInRootModule = "jvm"
//}
android {
namespace = "net.mamoe.mirai.internal"
}