Browse Source

Exclude mirai-core in :mirai-console:shadowJar

Karlatemp 5 years ago
parent
commit
5e3039f866

+ 13 - 0
backend/mirai-console/build.gradle.kts

@@ -71,6 +71,19 @@ dependencies {
     testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0")
     testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0")
 }
+ext {
+    // 傻逼 compileAndRuntime 没 exclude 掉
+    val x: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.() -> Unit = {
+        dependencyFilter.exclude {
+            when ("${it.moduleGroup}:${it.moduleName}") {
+                "net.mamoe:mirai-core" -> true
+                "net.mamoe:mirai-core-qqandroid" -> true
+                else -> false
+            }
+        }
+    }
+    this.set("shadowJar", x)
+}
 
 tasks {
     "test"(Test::class) {

+ 5 - 0
buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt

@@ -22,6 +22,7 @@ import kotlin.math.pow
 class MiraiConsoleBuildPlugin : Plugin<Project> {
     override fun apply(target: Project) = target.run {
         apply<ShadowPlugin>()
+        val ext = target.extensions.getByName("ext") as org.gradle.api.plugins.ExtraPropertiesExtension
 
         if (tasks.none { it.name == "shadowJar" }) {
             return@run
@@ -40,6 +41,10 @@ class MiraiConsoleBuildPlugin : Plugin<Project> {
                         "Implementation-Version" to target.version.toString() + "-" + gitVersion
                     )
                 }
+                @Suppress("UNCHECKED_CAST")
+                kotlin.runCatching {
+                    (ext["shadowJar"] as? ShadowJar.() -> Unit)?.invoke(this)
+                }
             }
         }