build.gradle.kts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. @file:Suppress("UnusedImport")
  10. plugins {
  11. kotlin("jvm")
  12. id("java-gradle-plugin")
  13. }
  14. dependencies {
  15. implementation(gradleApi())
  16. implementation(gradleKotlinDsl())
  17. implementation(`kotlin-reflect`)
  18. implementation(kotlin("gradle-plugin-api"))
  19. implementation(kotlin("gradle-plugin"))
  20. implementation(kotlin("stdlib"))
  21. api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
  22. api(`jetbrains-annotations`)
  23. testImplementation(kotlin("test-junit5"))
  24. testImplementation(`junit-jupiter-api`)
  25. testImplementation(`junit-jupiter-params`)
  26. testRuntimeOnly(`junit-jupiter-engine`)
  27. }
  28. tasks.getByName("test", Test::class) {
  29. environment("mirai.root.project.dir", rootProject.projectDir.absolutePath)
  30. systemProperty("mirai.deps.test.must.run", System.getProperty("mirai.deps.test.must.run"))
  31. }
  32. val publishMiraiArtifactsToMavenLocal by tasks.registering {
  33. group = "mirai"
  34. description = "Publish all mirai artifacts to MavenLocal"
  35. val publishTasks = rootProject.allprojects.mapNotNull { proj ->
  36. proj.tasks.findByName("publishToMavenLocal")
  37. }
  38. dependsOn(publishTasks)
  39. doFirst {
  40. // Always print this very important message
  41. logger.warn("[publishMiraiArtifactsToMavenLocal] Project version is '${project.version}'.")
  42. }
  43. }
  44. tasks.getByName("test") {
  45. mustRunAfter(publishMiraiArtifactsToMavenLocal)
  46. }
  47. tasks.register("updateProjectVersionForLocalDepsTest") {
  48. doLast {
  49. setProjectVersionForFutureBuilds(DEPS_TEST_VERSION)
  50. }
  51. }
  52. tasks.register("generateBuildConfig") {
  53. group = "mirai"
  54. doLast {
  55. generateBuildConfig()
  56. }
  57. tasks.getByName("testClasses").dependsOn(this)
  58. tasks.getByName("compileTestKotlin").dependsOn(this)
  59. }
  60. generateBuildConfig() // somehow "generateBuildConfig" won't execute
  61. fun generateBuildConfig() {
  62. val text = """
  63. package net.mamoe.mirai.deps.test
  64. /**
  65. * This file was generated by Gradle task `generateBuildConfig`.
  66. */
  67. object BuildConfig {
  68. /**
  69. * Kotlin version used to compile mirai-core
  70. */
  71. const val kotlinVersion = "${Versions.kotlinCompiler}"
  72. }
  73. """.trimIndent() + "\n"
  74. val file = project.projectDir.resolve("test/BuildConfig.kt")
  75. if (!file.exists() || file.readText() != text) {
  76. file.writeText(text)
  77. }
  78. }
  79. /**
  80. * Kind note: To run this task you probably need a lot of host memory and luck.
  81. *
  82. * **If you see errors, don't panic, that's most probably not your fault.**
  83. *
  84. * Try:
  85. *
  86. * ```shell
  87. * ./gradlew :mirai-deps-test:updateProjectVersionForLocalDepsTest
  88. * ./gradlew clean :mirai-deps-test:publishMiraiArtifactsToMavenLocal "-Porg.gradle.parallel=false"
  89. * ```
  90. * Note this will change your project version in `buildSrc/src/main/kotlin/Versions.kt`. Be careful to change it back before committing!
  91. * Note also this is **extremely slow**. If your computer isn't good enough it may take hours.
  92. */
  93. val publishMiraiLocalArtifacts = tasks.register("publishMiraiLocalArtifacts", Exec::class) {
  94. group = "mirai"
  95. description = "Starts a child process to publish v$DEPS_TEST_VERSION artifacts to MavenLocal"
  96. workingDir(rootProject.projectDir)
  97. environment("mirai.build.project.version", DEPS_TEST_VERSION)
  98. commandLine(
  99. "./gradlew",
  100. "clean",
  101. publishMiraiArtifactsToMavenLocal.name,
  102. "--no-daemon",
  103. "--stacktrace",
  104. "--scan",
  105. "-Pkotlin.compiler.execution.strategy=in-process"
  106. )
  107. standardOutput = System.out
  108. errorOutput = System.err
  109. }
  110. version = Versions.core