settings.gradle.kts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. 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. rootProject.name = "mirai"
  29. val localProperties = Properties().apply {
  30. rootProject.projectDir.resolve("local.properties").takeIf { it.exists() }?.bufferedReader()?.use {
  31. load(it)
  32. }
  33. }
  34. /**
  35. * Projects included so far
  36. */
  37. val allProjects = mutableListOf<ProjectDescriptor>()
  38. fun includeProject(projectPath: String, dir: String? = null) {
  39. if (!getLocalProperty("projects." + projectPath.removePrefix(":") + ".enabled", true)) return
  40. include(projectPath)
  41. if (dir != null) project(projectPath).projectDir = file(dir)
  42. allProjects.add(project(projectPath))
  43. }
  44. fun includeConsoleProject(projectPath: String, dir: String? = null) =
  45. includeProject(projectPath, "mirai-console/$dir")
  46. includeProject(":mirai-core-utils")
  47. includeProject(":mirai-core-api")
  48. includeProject(":mirai-core")
  49. includeProject(":mirai-core-mock")
  50. includeProject(":mirai-core-all")
  51. includeProject(":mirai-bom")
  52. includeProject(":mirai-dokka")
  53. includeProject(":mirai-deps-test")
  54. if (getLocalProperty("projects.mirai-logging.enabled", true)) {
  55. includeProject(":mirai-logging-log4j2", "logging/mirai-logging-log4j2")
  56. includeProject(":mirai-logging-slf4j", "logging/mirai-logging-slf4j")
  57. includeProject(":mirai-logging-slf4j-simple", "logging/mirai-logging-slf4j-simple")
  58. includeProject(":mirai-logging-slf4j-logback", "logging/mirai-logging-slf4j-logback")
  59. }
  60. // mirai-core-api depends on this
  61. includeConsoleProject(":mirai-console-compiler-annotations", "tools/compiler-annotations")
  62. if (getLocalProperty("projects.mirai-console.enabled", true)) {
  63. includeConsoleProject(":mirai-console", "backend/mirai-console")
  64. includeConsoleProject(":mirai-console.codegen", "backend/codegen")
  65. includeConsoleProject(":mirai-console-frontend-base", "frontend/mirai-console-frontend-base")
  66. includeConsoleProject(":mirai-console-terminal", "frontend/mirai-console-terminal")
  67. includeConsoleIntegrationTestProjects()
  68. includeConsoleProject(":mirai-console-compiler-common", "tools/compiler-common")
  69. includeConsoleProject(":mirai-console-intellij", "tools/intellij-plugin")
  70. includeConsoleProject(":mirai-console-gradle", "tools/gradle-plugin")
  71. } else {
  72. // if mirai-console is disabled, disable all relevant projects
  73. }
  74. //includeConsoleFrontendGraphical()
  75. includeProject(":ci-release-helper")
  76. includeBinaryCompatibilityValidatorProjects()
  77. /**
  78. * Configures a project `:validator:path-to-project:target-name` for binary compatibility validation.
  79. *
  80. * To enable validation for a project,
  81. * create a subdirectory with name of the target under "compatibility-validation",
  82. * then sync **twice**. See `:mirai-core-api` for an example.
  83. *
  84. * **Note**: This function depends on [allProjects], and should be used at the end.
  85. */
  86. fun includeBinaryCompatibilityValidatorProjects() {
  87. val result = mutableListOf<ProjectDescriptor>()
  88. for (project in allProjects) {
  89. val validationDir = project.projectDir.resolve("compatibility-validation")
  90. if (!validationDir.exists()) continue
  91. validationDir.listFiles().orEmpty<File>().forEach { dir ->
  92. if (dir.resolve("build.gradle.kts").isFile) {
  93. val path = ":validator" + project.path + ":${dir.name}"
  94. include(path)
  95. project(path).projectDir = dir
  96. // project(path).name = "${project.name}-validator-${dir.name}"
  97. result.add(project(path))
  98. }
  99. }
  100. }
  101. }
  102. fun includeConsoleLegacyFrontendProjects() {
  103. println("JDK version: ${JavaVersion.current()}")
  104. if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
  105. includeConsoleProject(":mirai-console-graphical", "frontend/mirai-console-graphical")
  106. } else {
  107. println("当前使用的 JDK 版本为 ${System.getProperty("java.version")}, 请使用 JDK 9 以上版本引入模块 `:mirai-console-graphical`\n")
  108. }
  109. }
  110. fun includeConsoleIntegrationTestProjects() {
  111. includeConsoleProject(":mirai-console.integration-test", "backend/integration-test")
  112. val consoleIntegrationTestSubPluginBuildGradleKtsTemplate by lazy {
  113. rootProject.projectDir
  114. .resolve("mirai-console/backend/integration-test/testers")
  115. .resolve("tester.template.gradle.kts")
  116. .readText()
  117. }
  118. @Suppress("SimpleRedundantLet")
  119. fun includeConsoleITPlugin(prefix: String, path: File) {
  120. path.resolve("build.gradle.kts").takeIf { !it.isFile }?.let { initScript ->
  121. initScript.writeText(consoleIntegrationTestSubPluginBuildGradleKtsTemplate)
  122. }
  123. val projectPath = "$prefix${path.name}"
  124. include(projectPath)
  125. project(projectPath).projectDir = path
  126. path.listFiles()?.asSequence().orEmpty()
  127. .filter { it.isDirectory }
  128. .filter { it.resolve(".nested-module.txt").exists() }
  129. .forEach { includeConsoleITPlugin("${projectPath}:", it) }
  130. }
  131. rootProject.projectDir
  132. .resolve("mirai-console/backend/integration-test/testers")
  133. .listFiles()?.asSequence().orEmpty()
  134. .filter { it.isDirectory }
  135. .forEach { includeConsoleITPlugin(":mirai-console.integration-test:", it) }
  136. }
  137. fun getLocalProperty(name: String): String? {
  138. return localProperties.getProperty(name)
  139. }
  140. fun getLocalProperty(name: String, default: String): String {
  141. return localProperties.getProperty(name) ?: default
  142. }
  143. fun getLocalProperty(name: String, default: Int): Int {
  144. return localProperties.getProperty(name)?.toInt() ?: default
  145. }
  146. fun getLocalProperty(name: String, default: Boolean): Boolean {
  147. return localProperties.getProperty(name)?.toBoolean() ?: default
  148. }