2
0

build.gradle.kts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright 2019-2022 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/dev/LICENSE
  8. */
  9. @file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE", "NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
  10. import org.jetbrains.dokka.base.DokkaBase
  11. import org.jetbrains.dokka.base.DokkaBaseConfiguration
  12. import java.time.LocalDateTime
  13. buildscript {
  14. repositories {
  15. if (System.getProperty("use.maven.local") == "true") {
  16. mavenLocal()
  17. }
  18. mavenCentral()
  19. gradlePluginPortal()
  20. google()
  21. }
  22. dependencies {
  23. classpath("com.android.tools.build:gradle:${Versions.androidGradlePlugin}")
  24. classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.atomicFU}")
  25. classpath("org.jetbrains.dokka:dokka-base:${Versions.dokka}")
  26. }
  27. }
  28. plugins {
  29. kotlin("jvm") apply false // version Versions.kotlinCompiler
  30. kotlin("plugin.serialization") version Versions.kotlinCompiler apply false
  31. id("com.google.osdetector")
  32. id("org.jetbrains.dokka") version Versions.dokka
  33. id("me.him188.kotlin-jvm-blocking-bridge") version Versions.blockingBridge
  34. id("me.him188.kotlin-dynamic-delegation") version Versions.dynamicDelegation apply false
  35. id("me.him188.maven-central-publish") version Versions.mavenCentralPublish apply false
  36. id("com.gradle.plugin-publish") version "1.0.0-rc-3" apply false
  37. id("org.jetbrains.kotlinx.binary-compatibility-validator") version Versions.binaryValidator apply false
  38. }
  39. osDetector = osdetector
  40. BuildSrcRootProjectHolder.value = rootProject
  41. analyzes.CompiledCodeVerify.run { registerAllVerifyTasks() }
  42. allprojects {
  43. group = "net.mamoe"
  44. version = Versions.project
  45. repositories {
  46. if (System.getProperty("use.maven.local") == "true") {
  47. mavenLocal()
  48. }
  49. mavenCentral()
  50. gradlePluginPortal()
  51. google()
  52. }
  53. preConfigureJvmTarget()
  54. afterEvaluate {
  55. configureJvmTarget()
  56. configureMppShadow()
  57. configureEncoding()
  58. configureKotlinTestSettings()
  59. configureKotlinExperimentalUsages()
  60. runCatching {
  61. blockingBridge {
  62. unitCoercion = me.him188.kotlin.jvm.blocking.bridge.compiler.UnitCoercion.COMPATIBILITY
  63. }
  64. }
  65. // useIr()
  66. if (isKotlinJvmProject) {
  67. configureFlattenSourceSets()
  68. }
  69. configureJarManifest()
  70. substituteDependenciesUsingExpectedVersion()
  71. }
  72. }
  73. afterEvaluate {
  74. configureShadowDependenciesForPublishing()
  75. }
  76. subprojects {
  77. afterEvaluate {
  78. if (project.path == ":mirai-core-api") configureDokka()
  79. if (project.path == ":mirai-console") configureDokka()
  80. }
  81. }
  82. rootProject.configureDokka()
  83. tasks.register("cleanExceptIntellij") {
  84. group = "build"
  85. allprojects.forEach { proj ->
  86. if (proj.name != "mirai-console-intellij") {
  87. // Type mismatch
  88. // proj.tasks.findByName("clean")?.let(::dependsOn)
  89. proj.tasks.findByName("clean")?.let { dependsOn(it) }
  90. }
  91. }
  92. }
  93. extensions.findByName("buildScan")?.withGroovyBuilder {
  94. setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
  95. setProperty("termsOfServiceAgree", "yes")
  96. }
  97. fun Project.useIr() {
  98. kotlinCompilations?.forEach { kotlinCompilation ->
  99. kotlinCompilation.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
  100. }
  101. }
  102. fun Project.configureDokka() {
  103. val isRoot = this@configureDokka == rootProject
  104. if (!isRoot) {
  105. apply(plugin = "org.jetbrains.dokka")
  106. }
  107. tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
  108. pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
  109. this.footerMessage = """Copyright 2019-${
  110. LocalDateTime.now().year
  111. } <a href="https://github.com/mamoe">Mamoe Technologies</a> and contributors.
  112. Source code:
  113. <a href="https://github.com/mamoe/mirai">GitHub</a>
  114. """.trimIndent()
  115. this.customAssets = listOf(
  116. rootProject.projectDir.resolve("mirai-dokka/frontend/ext.js"),
  117. )
  118. }
  119. }
  120. tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
  121. dokkaSourceSets.configureEach {
  122. perPackageOption {
  123. matchingRegex.set("net\\.mamoe\\.mirai\\.*")
  124. skipDeprecated.set(true)
  125. }
  126. for (suppressedPackage in arrayOf(
  127. """net.mamoe.mirai.internal""",
  128. """net.mamoe.mirai.internal.message""",
  129. """net.mamoe.mirai.internal.network""",
  130. """net.mamoe.mirai.console.internal""",
  131. """net.mamoe.mirai.console.compiler.common"""
  132. )) {
  133. perPackageOption {
  134. matchingRegex.set(suppressedPackage.replace(".", "\\."))
  135. suppress.set(true)
  136. }
  137. }
  138. }
  139. }
  140. if (isRoot) {
  141. tasks.named<org.jetbrains.dokka.gradle.AbstractDokkaTask>("dokkaHtmlMultiModule").configure {
  142. outputDirectory.set(
  143. rootProject.projectDir.resolve("mirai-dokka/pages/snapshot")
  144. )
  145. }
  146. }
  147. }