From 2ef89d2b3f2e2b4aca62bba056d89e7a5a2e33b2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 1 May 2023 10:56:16 +0100 Subject: [PATCH] [build] Do not apply Android-relevant plugins if Android target is not enabled --- build.gradle.kts | 1 + buildSrc/src/main/kotlin/Android.kt | 11 ++++++++--- buildSrc/src/main/kotlin/HmppConfigure.kt | 4 ++-- .../tools/compiler-annotations/build.gradle.kts | 7 +------ mirai-core-api/build.gradle.kts | 7 +------ mirai-core-utils/build.gradle.kts | 9 ++------- mirai-core/build.gradle.kts | 8 +------- 7 files changed, 16 insertions(+), 31 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 471de18b3..9282da05e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 diff --git a/buildSrc/src/main/kotlin/Android.kt b/buildSrc/src/main/kotlin/Android.kt index 27f2abef8..13e834b94 100644 --- a/buildSrc/src/main/kotlin/Android.kt +++ b/buildSrc/src/main/kotlin/Android.kt @@ -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) { diff --git a/buildSrc/src/main/kotlin/HmppConfigure.kt b/buildSrc/src/main/kotlin/HmppConfigure.kt index 42fbff9fa..cbadc9b15 100644 --- a/buildSrc/src/main/kotlin/HmppConfigure.kt +++ b/buildSrc/src/main/kotlin/HmppConfigure.kt @@ -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")) { diff --git a/mirai-console/tools/compiler-annotations/build.gradle.kts b/mirai-console/tools/compiler-annotations/build.gradle.kts index b766f83e3..0b638ec30 100644 --- a/mirai-console/tools/compiler-annotations/build.gradle.kts +++ b/mirai-console/tools/compiler-annotations/build.gradle.kts @@ -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" -} \ No newline at end of file diff --git a/mirai-core-api/build.gradle.kts b/mirai-core-api/build.gradle.kts index 26e3d2149..79468eaef 100644 --- a/mirai-core-api/build.gradle.kts +++ b/mirai-core-api/build.gradle.kts @@ -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" -} \ No newline at end of file diff --git a/mirai-core-utils/build.gradle.kts b/mirai-core-utils/build.gradle.kts index b3317b976..589c956f2 100644 --- a/mirai-core-utils/build.gradle.kts +++ b/mirai-core-utils/build.gradle.kts @@ -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" -} \ No newline at end of file +//} \ No newline at end of file diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts index 3f82762d3..24e792eab 100644 --- a/mirai-core/build.gradle.kts +++ b/mirai-core/build.gradle.kts @@ -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" -} \ No newline at end of file