build.gradle.kts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/master/LICENSE
  8. */
  9. @file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE", "NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
  10. import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
  11. import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
  12. import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
  13. buildscript {
  14. repositories {
  15. mavenLocal()
  16. // maven(url = "https://mirrors.huaweicloud.com/repository/maven")
  17. mavenCentral()
  18. jcenter()
  19. google()
  20. maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
  21. maven(url = "https://kotlin.bintray.com/kotlinx")
  22. }
  23. dependencies {
  24. classpath("com.android.tools.build:gradle:${Versions.androidGradlePlugin}")
  25. classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.atomicFU}")
  26. classpath("org.jetbrains.kotlinx:binary-compatibility-validator:${Versions.binaryValidator}")
  27. }
  28. }
  29. plugins {
  30. kotlin("jvm") // version Versions.kotlinCompiler
  31. kotlin("plugin.serialization") version Versions.kotlinCompiler
  32. // id("org.jetbrains.dokka") version Versions.dokka
  33. id("net.mamoe.kotlin-jvm-blocking-bridge") version Versions.blockingBridge
  34. id("com.jfrog.bintray") // version Versions.bintray
  35. id("com.gradle.plugin-publish") version "0.12.0" apply false
  36. }
  37. // https://github.com/kotlin/binary-compatibility-validator
  38. apply(plugin = "binary-compatibility-validator")
  39. configure<kotlinx.validation.ApiValidationExtension> {
  40. allprojects.forEach { subproject ->
  41. ignoredProjects.add(subproject.name)
  42. }
  43. ignoredProjects.remove("binary-compatibility-validator")
  44. ignoredProjects.remove("binary-compatibility-validator-android")
  45. // Enable validator for module `binary-compatibility-validator` and `-android` only.
  46. ignoredPackages.add("net.mamoe.mirai.internal")
  47. ignoredPackages.add("net.mamoe.mirai.console.internal")
  48. nonPublicMarkers.add("net.mamoe.mirai.MiraiInternalApi")
  49. nonPublicMarkers.add("net.mamoe.mirai.console.utils.ConsoleInternalApi")
  50. nonPublicMarkers.add("net.mamoe.mirai.console.utils.ConsoleExperimentalApi")
  51. nonPublicMarkers.add("net.mamoe.mirai.MiraiExperimentalApi")
  52. }
  53. GpgSigner.setup(project)
  54. tasks.register("publishMiraiCoreArtifactsToMavenLocal") {
  55. group = "mirai"
  56. dependsOn(
  57. project(":mirai-core-api").tasks.getByName("publishToMavenLocal"),
  58. project(":mirai-core-utils").tasks.getByName("publishToMavenLocal"),
  59. project(":mirai-core").tasks.getByName("publishToMavenLocal")
  60. )
  61. }
  62. allprojects {
  63. group = "net.mamoe"
  64. version = Versions.project
  65. repositories {
  66. // mavenLocal() // cheching issue cause compiler exception
  67. // maven(url = "https://mirrors.huaweicloud.com/repository/maven")
  68. jcenter()
  69. maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
  70. maven(url = "https://kotlin.bintray.com/kotlinx")
  71. google()
  72. mavenCentral()
  73. }
  74. afterEvaluate {
  75. configureJvmTarget()
  76. configureMppShadow()
  77. configureEncoding()
  78. configureKotlinTestSettings()
  79. configureKotlinCompilerSettings()
  80. configureKotlinExperimentalUsages()
  81. runCatching {
  82. blockingBridge {
  83. unitCoercion = net.mamoe.kjbb.compiler.UnitCoercion.COMPATIBILITY
  84. }
  85. }
  86. // useIr()
  87. if (isKotlinJvmProject) {
  88. configureFlattenSourceSets()
  89. }
  90. }
  91. }
  92. subprojects {
  93. afterEvaluate {
  94. if (project.name == "mirai-core-api") configureDokka()
  95. if (project.name == "mirai-console") configureDokka()
  96. }
  97. }
  98. tasks.register("cleanExceptIntellij") {
  99. group = "build"
  100. allprojects.forEach { proj ->
  101. if (proj.name != "mirai-console-intellij") {
  102. // Type mismatch
  103. // proj.tasks.findByName("clean")?.let(::dependsOn)
  104. proj.tasks.findByName("clean")?.let { dependsOn(it) }
  105. }
  106. }
  107. }
  108. extensions.findByName("buildScan")?.withGroovyBuilder {
  109. setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
  110. setProperty("termsOfServiceAgree", "yes")
  111. }
  112. fun Project.useIr() {
  113. kotlinCompilations?.forEach { kotlinCompilation ->
  114. kotlinCompilation.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
  115. }
  116. }
  117. fun Project.configureDokka() {
  118. // apply(plugin = "org.jetbrains.dokka")
  119. // tasks {
  120. // val dokkaHtml by getting(org.jetbrains.dokka.gradle.DokkaTask::class) {
  121. // outputDirectory.set(buildDir.resolve("dokka"))
  122. // }
  123. // val dokkaGfm by getting(org.jetbrains.dokka.gradle.DokkaTask::class) {
  124. // outputDirectory.set(buildDir.resolve("dokka-gfm"))
  125. // }
  126. // }
  127. // tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
  128. // dokkaSourceSets.configureEach {
  129. // perPackageOption {
  130. // matchingRegex.set("net\\.mamoe\\.mirai\\.*")
  131. // skipDeprecated.set(true)
  132. // }
  133. //
  134. // for (suppressedPackage in arrayOf(
  135. // """net.mamoe.mirai.internal""",
  136. // """net.mamoe.mirai.internal.message""",
  137. // """net.mamoe.mirai.internal.network""",
  138. // """net.mamoe.mirai.console.internal""",
  139. // """net.mamoe.mirai.console.compiler.common"""
  140. // )) {
  141. // perPackageOption {
  142. // matchingRegex.set(suppressedPackage.replace(".", "\\."))
  143. // suppress.set(true)
  144. // }
  145. // }
  146. // }
  147. // }
  148. }
  149. fun Project.configureMppShadow() {
  150. val kotlin =
  151. runCatching {
  152. (this as ExtensionAware).extensions.getByName("kotlin") as? KotlinMultiplatformExtension
  153. }.getOrNull() ?: return
  154. if (project.configurations.findByName("jvmRuntimeClasspath") != null) {
  155. val shadowJvmJar by tasks.creating(ShadowJar::class) sd@{
  156. group = "mirai"
  157. archiveClassifier.set("-all")
  158. val compilations =
  159. kotlin.targets.filter { it.platformType == KotlinPlatformType.jvm }
  160. .map { it.compilations["main"] }
  161. compilations.forEach {
  162. dependsOn(it.compileKotlinTask)
  163. from(it.output)
  164. }
  165. from(project.configurations.findByName("jvmRuntimeClasspath"))
  166. this.exclude { file ->
  167. file.name.endsWith(".sf", ignoreCase = true)
  168. }
  169. /*
  170. this.manifest {
  171. this.attributes(
  172. "Manifest-Version" to 1,
  173. "Implementation-Vendor" to "Mamoe Technologies",
  174. "Implementation-Title" to this.name.toString(),
  175. "Implementation-Version" to this.version.toString()
  176. )
  177. }*/
  178. }
  179. }
  180. }