From 3360347ca244c898bd54d9066d312cc6820c8564 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 27 Nov 2022 15:09:20 +0000 Subject: [PATCH] [build] Fix dependency exclusion for builds when IDEA_ACTIVE --- buildSrc/src/main/kotlin/Relocation.kt | 25 ++++++++++++------------- mirai-core-api/build.gradle.kts | 3 +-- mirai-core-utils/build.gradle.kts | 5 +---- mirai-core/build.gradle.kts | 1 - mirai-deps-test/build.gradle.kts | 16 +++++++++++++++- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/buildSrc/src/main/kotlin/Relocation.kt b/buildSrc/src/main/kotlin/Relocation.kt index 61d1d0c1e..8961a3b26 100644 --- a/buildSrc/src/main/kotlin/Relocation.kt +++ b/buildSrc/src/main/kotlin/Relocation.kt @@ -18,7 +18,6 @@ import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.invoke import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler -import java.io.File /** * # 非常重要的提示 — 有关 relocation — 在看完全部本文前, 不要进行任何操作 @@ -97,9 +96,9 @@ object RelocationNotes */ fun KotlinDependencyHandler.relocateCompileOnly( relocatedDependency: RelocatedDependency, - action: ExternalModuleDependency.() -> Unit = {} ): ExternalModuleDependency { - val dependency = compileOnly(relocatedDependency.notation, action) + val dependency = compileOnly(relocatedDependency.notation) { + } project.relocationFilters.add( RelocationFilter( dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false, @@ -120,9 +119,10 @@ fun KotlinDependencyHandler.relocateCompileOnly( fun DependencyHandler.relocateCompileOnly( project: Project, relocatedDependency: RelocatedDependency, - action: Action = Action {} ): Dependency { - val dependency = addDependencyTo(this, "compileOnly", relocatedDependency.notation, action) + val dependency = + addDependencyTo(this, "compileOnly", relocatedDependency.notation, Action { + }) project.relocationFilters.add( RelocationFilter( dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false, @@ -159,8 +159,7 @@ fun KotlinDependencyHandler.relocateImplementation( relocatedDependency.notation, Action { relocatedDependency.exclusionAction(this) - exclude(ExcludeProperties.`everything from kotlin`) - exclude(ExcludeProperties.`everything from kotlinx`) + intrinsicExclusions() action() } ) @@ -182,10 +181,6 @@ fun DependencyHandler.relocateImplementation( ): ExternalModuleDependency { val dependency = addDependencyTo(this, "implementation", relocatedDependency.notation, Action { - relocatedDependency.exclusionAction(this) - exclude(ExcludeProperties.`everything from kotlin`) - exclude(ExcludeProperties.`everything from kotlinx`) - action.execute(this) }) project.relocationFilters.add( RelocationFilter( @@ -199,14 +194,18 @@ fun DependencyHandler.relocateImplementation( relocatedDependency.notation, Action { relocatedDependency.exclusionAction(this) - exclude(ExcludeProperties.`everything from kotlin`) - exclude(ExcludeProperties.`everything from kotlinx`) + intrinsicExclusions() action(this) } ) return dependency } +private fun ExternalModuleDependency.intrinsicExclusions() { + exclude(ExcludeProperties.`everything from kotlin`) + exclude(ExcludeProperties.`everything from kotlinx`) +} + const val SHADOW_RELOCATION_CONFIGURATION_NAME = "shadowRelocation" diff --git a/mirai-core-api/build.gradle.kts b/mirai-core-api/build.gradle.kts index 8e39533aa..786e55568 100644 --- a/mirai-core-api/build.gradle.kts +++ b/mirai-core-api/build.gradle.kts @@ -43,7 +43,7 @@ kotlin { implementation(project(":mirai-core-utils")) implementation(project(":mirai-console-compiler-annotations")) implementation(`kotlinx-serialization-protobuf`) - relocateCompileOnly(`ktor-io_relocated`) // runtime from mirai-core-utils + compileOnly(`ktor-io`) // runtime from mirai-core-utils } } @@ -63,7 +63,6 @@ kotlin { } findByName("androidMain")?.apply { - dependsOn(commonMain) dependencies { compileOnly(`android-runtime`) } diff --git a/mirai-core-utils/build.gradle.kts b/mirai-core-utils/build.gradle.kts index ff8c6c99d..874d9ac1c 100644 --- a/mirai-core-utils/build.gradle.kts +++ b/mirai-core-utils/build.gradle.kts @@ -36,10 +36,7 @@ kotlin { api(`kotlinx-coroutines-core`) implementation(`kotlinx-serialization-protobuf`) - relocateImplementation(`ktor-io_relocated`) { - exclude(ExcludeProperties.`kotlin-stdlib`) - exclude(ExcludeProperties.`kotlinx-coroutines`) - } + relocateImplementation(`ktor-io_relocated`) } } diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts index 2ddf94eac..7ec851a2a 100644 --- a/mirai-core/build.gradle.kts +++ b/mirai-core/build.gradle.kts @@ -73,7 +73,6 @@ kotlin { } findByName("androidMain")?.apply { - dependsOn(commonMain) dependencies { compileOnly(`android-runtime`) } diff --git a/mirai-deps-test/build.gradle.kts b/mirai-deps-test/build.gradle.kts index f09cbaa01..1f489581f 100644 --- a/mirai-deps-test/build.gradle.kts +++ b/mirai-deps-test/build.gradle.kts @@ -98,7 +98,20 @@ fun generateBuildConfig() { } } -// keep this property for Search Everywhere +/** + * Kind note: To run this task you probably need a lot of host memory and luck. + * + * **If you see errors, don't panic, that's most probably not your fault.** + * + * Try: + * + * ```shell + * ./gradlew :mirai-deps-test:updateProjectVersionForLocalDepsTest + * ./gradlew clean :mirai-deps-test:publishMiraiArtifactsToMavenLocal "-Porg.gradle.parallel=false" + * ``` + * Note this will change your project version in `buildSrc/src/main/kotlin/Versions.kt`. Be careful to change it back before committing! + * Note also this is **extremely slow**. If your computer isn't good enough it may take hours. + */ val publishMiraiLocalArtifacts = tasks.register("publishMiraiLocalArtifacts", Exec::class) { group = "mirai" description = "Starts a child process to publish v$DEPS_TEST_VERSION artifacts to MavenLocal" @@ -107,6 +120,7 @@ val publishMiraiLocalArtifacts = tasks.register("publishMiraiLocalArtifacts", Ex environment("mirai.build.project.version", DEPS_TEST_VERSION) commandLine( "./gradlew", + "clean", publishMiraiArtifactsToMavenLocal.name, "--no-daemon", "--stacktrace",