settings.gradle.kts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright 2019-2023 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. import java.util.*
  10. /*
  11. * Copyright 2019-2022 Mamoe Technologies and contributors.
  12. *
  13. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  14. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  15. *
  16. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  17. */
  18. pluginManagement {
  19. repositories {
  20. if (System.getProperty("use.maven.local") == "true") { // you can enable by adding `systemProp.use.maven.local=true` in 'gradle.properties'.
  21. mavenLocal()
  22. }
  23. gradlePluginPortal()
  24. mavenCentral()
  25. google()
  26. }
  27. }
  28. plugins {
  29. id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
  30. }
  31. rootProject.name = "mirai"
  32. runCatching { rootProject.projectDir.resolve("local.properties").let { if (!it.exists()) it.createNewFile() } }
  33. val localProperties = Properties().apply {
  34. rootProject.projectDir.resolve("local.properties").takeIf { it.exists() }?.bufferedReader()?.use {
  35. load(it)
  36. }
  37. }
  38. /**
  39. * Projects included so far
  40. */
  41. val allProjects = mutableListOf<ProjectDescriptor>()
  42. fun includeProject(projectPath: String, dir: String? = null) {
  43. if (!getLocalProperty("projects." + projectPath.removePrefix(":") + ".enabled", true)) return
  44. include(projectPath)
  45. if (dir != null) project(projectPath).projectDir = file(dir)
  46. allProjects.add(project(projectPath))
  47. }
  48. fun includeConsoleProject(projectPath: String, dir: String? = null) =
  49. includeProject(projectPath, "mirai-console/$dir")
  50. includeProject(":mirai-core-utils")
  51. includeProject(":mirai-core-api")
  52. includeProject(":mirai-core")
  53. includeProject(":mirai-core-mock")
  54. includeProject(":mirai-core-all")
  55. includeProject(":mirai-bom")
  56. includeProject(":mirai-dokka")
  57. includeProject(":mirai-deps-test")
  58. if (getLocalProperty("projects.mirai-logging.enabled", true)) {
  59. includeProject(":mirai-logging-log4j2", "logging/mirai-logging-log4j2")
  60. includeProject(":mirai-logging-slf4j", "logging/mirai-logging-slf4j")
  61. includeProject(":mirai-logging-slf4j-simple", "logging/mirai-logging-slf4j-simple")
  62. includeProject(":mirai-logging-slf4j-logback", "logging/mirai-logging-slf4j-logback")
  63. }
  64. // mirai-core-api depends on this
  65. includeConsoleProject(":mirai-console-compiler-annotations", "tools/compiler-annotations")
  66. if (getLocalProperty("projects.mirai-console.enabled", true)) {
  67. includeConsoleProject(":mirai-console", "backend/mirai-console")
  68. includeConsoleProject(":mirai-console.codegen", "backend/codegen")
  69. includeConsoleProject(":mirai-console-frontend-base", "frontend/mirai-console-frontend-base")
  70. includeConsoleProject(":mirai-console-terminal", "frontend/mirai-console-terminal")
  71. includeConsoleIntegrationTestProjects()
  72. includeConsoleProject(":mirai-console-compiler-common", "tools/compiler-common")
  73. includeConsoleProject(":mirai-console-intellij", "tools/intellij-plugin")
  74. includeConsoleProject(":mirai-console-gradle", "tools/gradle-plugin")
  75. } else {
  76. // if mirai-console is disabled, disable all relevant projects
  77. }
  78. //includeConsoleFrontendGraphical()
  79. includeProject(":ci-release-helper")
  80. includeBinaryCompatibilityValidatorProjects()
  81. /**
  82. * Configures a project `:validator:path-to-project:target-name` for binary compatibility validation.
  83. *
  84. * To enable validation for a project,
  85. * create a subdirectory with name of the target under "compatibility-validation",
  86. * then sync **twice**. See `:mirai-core-api` for an example.
  87. *
  88. * **Note**: This function depends on [allProjects], and should be used at the end.
  89. */
  90. fun includeBinaryCompatibilityValidatorProjects() {
  91. val result = mutableListOf<ProjectDescriptor>()
  92. for (project in allProjects) {
  93. val validationDir = project.projectDir.resolve("compatibility-validation")
  94. if (!validationDir.exists()) continue
  95. validationDir.listFiles().orEmpty<File>().forEach { dir ->
  96. if (dir.resolve("build.gradle.kts").isFile) {
  97. // Also change: BinaryCompatibilityConfigurator.getValidatorDir
  98. val path = ":validator" + project.path + "-validator:${dir.name}"
  99. include(path)
  100. project(path).projectDir = dir
  101. // project(path).name = "${project.name}-validator-${dir.name}"
  102. result.add(project(path))
  103. }
  104. }
  105. }
  106. }
  107. fun includeConsoleLegacyFrontendProjects() {
  108. println("JDK version: ${JavaVersion.current()}")
  109. if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
  110. includeConsoleProject(":mirai-console-graphical", "frontend/mirai-console-graphical")
  111. } else {
  112. println("当前使用的 JDK 版本为 ${System.getProperty("java.version")}, 请使用 JDK 9 以上版本引入模块 `:mirai-console-graphical`\n")
  113. }
  114. }
  115. fun includeConsoleIntegrationTestProjects() {
  116. includeConsoleProject(":mirai-console.integration-test", "backend/integration-test")
  117. val consoleIntegrationTestSubPluginBuildGradleKtsTemplate by lazy {
  118. rootProject.projectDir
  119. .resolve("mirai-console/backend/integration-test/testers")
  120. .resolve("tester.template.gradle.kts")
  121. .readText()
  122. }
  123. @Suppress("SimpleRedundantLet")
  124. fun includeConsoleITPlugin(prefix: String, path: File) {
  125. path.resolve("build.gradle.kts").takeIf { !it.isFile }?.let { initScript ->
  126. initScript.writeText(consoleIntegrationTestSubPluginBuildGradleKtsTemplate)
  127. }
  128. val projectPath = "$prefix${path.name}"
  129. include(projectPath)
  130. project(projectPath).projectDir = path
  131. path.listFiles()?.asSequence().orEmpty()
  132. .filter { it.isDirectory }
  133. .filter { it.resolve(".nested-module.txt").exists() }
  134. .forEach { includeConsoleITPlugin("${projectPath}:", it) }
  135. }
  136. rootProject.projectDir
  137. .resolve("mirai-console/backend/integration-test/testers")
  138. .listFiles()?.asSequence().orEmpty()
  139. .filter { it.isDirectory }
  140. .forEach { includeConsoleITPlugin(":mirai-console.integration-test:", it) }
  141. }
  142. fun getLocalProperty(name: String): String? {
  143. return localProperties.getProperty(name)
  144. }
  145. fun getLocalProperty(name: String, default: String): String {
  146. return localProperties.getProperty(name) ?: default
  147. }
  148. fun getLocalProperty(name: String, default: Int): Int {
  149. return localProperties.getProperty(name)?.toInt() ?: default
  150. }
  151. fun getLocalProperty(name: String, default: Boolean): Boolean {
  152. return localProperties.getProperty(name)?.toBoolean() ?: default
  153. }