Browse Source

[build] Fix dependency exclusion for builds when IDEA_ACTIVE

Him188 3 years ago
parent
commit
a3fc1857c2

+ 12 - 13
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<ExternalModuleDependency> = Action {}
 ): Dependency {
-    val dependency = addDependencyTo(this, "compileOnly", relocatedDependency.notation, action)
+    val dependency =
+        addDependencyTo(this, "compileOnly", relocatedDependency.notation, Action<ExternalModuleDependency> {
+        })
     project.relocationFilters.add(
         RelocationFilter(
             dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false,
@@ -159,8 +159,7 @@ fun KotlinDependencyHandler.relocateImplementation(
         relocatedDependency.notation,
         Action<ExternalModuleDependency> {
             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<ExternalModuleDependency> {
-            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<ExternalModuleDependency> {
             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"
 

+ 1 - 3
mirai-core-api/build.gradle.kts

@@ -43,8 +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
-                implementation(`ktor-io`)
+                compileOnly(`ktor-io`) // runtime from mirai-core-utils
             }
         }
 
@@ -64,7 +63,6 @@ kotlin {
         }
 
         findByName("androidMain")?.apply {
-            dependsOn(commonMain)
             dependencies {
                 compileOnly(`android-runtime`)
             }

+ 1 - 4
mirai-core-utils/build.gradle.kts

@@ -37,10 +37,7 @@ kotlin {
 
                 implementation(`kotlinx-atomicfu`)
                 implementation(`kotlinx-serialization-protobuf`)
-                relocateImplementation(`ktor-io_relocated`) {
-                    exclude(ExcludeProperties.`kotlin-stdlib`)
-                    exclude(ExcludeProperties.`kotlinx-coroutines`)
-                }
+                relocateImplementation(`ktor-io_relocated`)
             }
         }
 

+ 0 - 1
mirai-core/build.gradle.kts

@@ -74,7 +74,6 @@ kotlin {
         }
 
         findByName("androidMain")?.apply {
-            dependsOn(commonMain)
             dependencies {
                 compileOnly(`android-runtime`)
             }

+ 15 - 1
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",