浏览代码

Optimize build script

ryoii 4 年之前
父节点
当前提交
f366c71329
共有 2 个文件被更改,包括 22 次插入43 次删除
  1. 4 2
      gradle.properties
  2. 18 41
      mirai-api-http/build.gradle.kts

+ 4 - 2
gradle.properties

@@ -2,13 +2,15 @@
 kotlin.code.style=official
 # config
 kotlin.incremental.multiplatform=true
-kotlin.parallel.tasks.in.project=true
-
+org.gradle.parallel=true
 
 # build
 httpVersion=2.3.3
 
 # kotlin
 kotlinVersion=1.5.30
+kotlin.stdlib.default.dependency=false
+
+# ktor
 ktorVersion=1.5.4
 atomicFuVersion=0.16.3

+ 18 - 41
mirai-api-http/build.gradle.kts

@@ -7,16 +7,21 @@ plugins {
 }
 
 val ktorVersion: String by rootProject.extra
-val atomicFuVersion: String by rootProject.extra
-fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
-fun ktor(id: String, version: String = this@Build_gradle.ktorVersion) = "io.ktor:ktor-$id:$version"
+fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.ktorApi(id: String, version: String = ktorVersion) {
+    api("io.ktor:ktor-$id:$version") {
+        exclude(group = "org.jetbrains.kotlin")
+        exclude(group = "org.jetbrains.kotlinx")
+        exclude(module = "slf4j-api")
+    }
+}
 
 kotlin {
     sourceSets["test"].apply {
         dependencies {
+            api("net.mamoe.yamlkt:yamlkt:0.9.0")
             api("org.slf4j:slf4j-simple:1.7.26")
             api(kotlin("test-junit5"))
-            api(ktor("server-test-host"))
+            ktorApi("server-test-host")
         }
     }
 
@@ -25,17 +30,14 @@ kotlin {
         languageSettings.optIn("kotlin.Experimental")
 
         dependencies {
-
-            // 支持到 localMode 调试使用, 打包时排除
-            api("net.mamoe.yamlkt:yamlkt:0.9.0")
-
-            api(ktor("server-cio"))
-            api(ktor("http-jvm"))
-            api(ktor("websockets"))
-            api(ktor("client-websockets"))
-
-            api(ktor("server-core"))
-            api(ktor("http"))
+            compileOnly("net.mamoe.yamlkt:yamlkt:0.9.0")
+            
+            ktorApi("server-cio")
+            ktorApi("http-jvm")
+            ktorApi("websockets")
+            ktorApi("client-websockets")
+            ktorApi("server-core")
+            ktorApi("http")
         }
     }
 }
@@ -45,24 +47,7 @@ project.version = httpVersion
 
 description = "Mirai HTTP API plugin"
 
-internal val excluded = listOf(
-    "kotlin-stdlib-.*",
-    "kotlin-reflect-.*",
-    "kotlinx-serialization-json.*",
-    "kotlinx-coroutines.*",
-    "kotlinx-serialization-core.*",
-    "slf4j-api.*"
-).map { "^$it\$".toRegex() }
-
-mirai {
-    this.configureShadow {
-        exclude { elm ->
-            excluded.any { it.matches(elm.path) }
-        }
-    }
-}
-
-tasks.create("buildCiJar", Jar::class) {
+tasks.register("buildCiJar", Jar::class) {
     dependsOn("buildPlugin")
     doLast {
         val buildPluginTask = tasks.getByName("buildPlugin", Jar::class)
@@ -84,14 +69,6 @@ mavenCentralPublish {
     licenseFromGitHubProject("licenseAgplv3", "master")
 }
 
-dependencies {
-    implementation(kotlin("stdlib-jdk8"))
-}
-
-repositories {
-    mavenCentral()
-}
-
 tasks {
     compileKotlin {
         kotlinOptions.jvmTarget = "1.8"