2
0

build.gradle.kts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. configureKotlinExperimentalUsages()
  80. runCatching {
  81. blockingBridge {
  82. unitCoercion = net.mamoe.kjbb.compiler.UnitCoercion.COMPATIBILITY
  83. }
  84. }
  85. // useIr()
  86. if (isKotlinJvmProject) {
  87. configureFlattenSourceSets()
  88. }
  89. }
  90. }
  91. subprojects {
  92. afterEvaluate {
  93. if (project.name == "mirai-core-api") configureDokka()
  94. if (project.name == "mirai-console") configureDokka()
  95. }
  96. }
  97. tasks.register("cleanExceptIntellij") {
  98. group = "build"
  99. allprojects.forEach { proj ->
  100. if (proj.name != "mirai-console-intellij") {
  101. // Type mismatch
  102. // proj.tasks.findByName("clean")?.let(::dependsOn)
  103. proj.tasks.findByName("clean")?.let { dependsOn(it) }
  104. }
  105. }
  106. }
  107. extensions.findByName("buildScan")?.withGroovyBuilder {
  108. setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
  109. setProperty("termsOfServiceAgree", "yes")
  110. }
  111. fun Project.useIr() {
  112. kotlinCompilations?.forEach { kotlinCompilation ->
  113. kotlinCompilation.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
  114. }
  115. }
  116. fun Project.configureDokka() {
  117. // apply(plugin = "org.jetbrains.dokka")
  118. // tasks {
  119. // val dokkaHtml by getting(org.jetbrains.dokka.gradle.DokkaTask::class) {
  120. // outputDirectory.set(buildDir.resolve("dokka"))
  121. // }
  122. // val dokkaGfm by getting(org.jetbrains.dokka.gradle.DokkaTask::class) {
  123. // outputDirectory.set(buildDir.resolve("dokka-gfm"))
  124. // }
  125. // }
  126. // tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
  127. // dokkaSourceSets.configureEach {
  128. // perPackageOption {
  129. // matchingRegex.set("net\\.mamoe\\.mirai\\.*")
  130. // skipDeprecated.set(true)
  131. // }
  132. //
  133. // for (suppressedPackage in arrayOf(
  134. // """net.mamoe.mirai.internal""",
  135. // """net.mamoe.mirai.internal.message""",
  136. // """net.mamoe.mirai.internal.network""",
  137. // """net.mamoe.mirai.console.internal""",
  138. // """net.mamoe.mirai.console.compiler.common"""
  139. // )) {
  140. // perPackageOption {
  141. // matchingRegex.set(suppressedPackage.replace(".", "\\."))
  142. // suppress.set(true)
  143. // }
  144. // }
  145. // }
  146. // }
  147. }
  148. fun Project.configureMppShadow() {
  149. val kotlin =
  150. runCatching {
  151. (this as ExtensionAware).extensions.getByName("kotlin") as? KotlinMultiplatformExtension
  152. }.getOrNull() ?: return
  153. if (project.configurations.findByName("jvmRuntimeClasspath") != null) {
  154. val shadowJvmJar by tasks.creating(ShadowJar::class) sd@{
  155. group = "mirai"
  156. archiveClassifier.set("-all")
  157. val compilations =
  158. kotlin.targets.filter { it.platformType == KotlinPlatformType.jvm }
  159. .map { it.compilations["main"] }
  160. compilations.forEach {
  161. dependsOn(it.compileKotlinTask)
  162. from(it.output)
  163. }
  164. from(project.configurations.findByName("jvmRuntimeClasspath"))
  165. this.exclude { file ->
  166. file.name.endsWith(".sf", ignoreCase = true)
  167. }
  168. /*
  169. this.manifest {
  170. this.attributes(
  171. "Manifest-Version" to 1,
  172. "Implementation-Vendor" to "Mamoe Technologies",
  173. "Implementation-Title" to this.name.toString(),
  174. "Implementation-Version" to this.version.toString()
  175. )
  176. }*/
  177. }
  178. }
  179. fun Project.configureEncoding() {
  180. tasks.withType(JavaCompile::class.java) {
  181. options.encoding = "UTF8"
  182. }
  183. }
  184. fun Project.configureKotlinTestSettings() {
  185. tasks.withType(Test::class) {
  186. useJUnitPlatform()
  187. }
  188. when {
  189. isKotlinJvmProject -> {
  190. dependencies {
  191. testImplementation(kotlin("test-junit5"))
  192. testApi("org.junit.jupiter:junit-jupiter-api:5.2.0")
  193. testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0")
  194. }
  195. }
  196. isKotlinMpp -> {
  197. kotlinSourceSets?.forEach { sourceSet ->
  198. if (sourceSet.name.endsWith("test", ignoreCase = true)) {
  199. sourceSet.dependencies {
  200. api(kotlin("test-junit5"))
  201. api("org.junit.jupiter:junit-jupiter-api:5.2.0")
  202. runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0")
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }