2
0

build.gradle.kts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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("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. doLast {
  44. // delete shadowed Jars, since Kotlin can't compile modules that depend on them.
  45. rootProject.subprojects
  46. .asSequence()
  47. .flatMap { proj -> proj.tasks.filter { task -> task.name.contains("relocate") } }
  48. .flatMap { it.outputs.files }
  49. .filter { it.isFile && it.name.endsWith(".jar") }
  50. .forEach { it.delete() }
  51. }
  52. }
  53. tasks.register("updateProjectVersionForLocalDepsTest") {
  54. doLast {
  55. setProjectVersionForFutureBuilds(DEPS_TEST_VERSION)
  56. }
  57. }
  58. tasks.register("generateBuildConfig") {
  59. group = "mirai"
  60. doLast {
  61. generateBuildConfig()
  62. }
  63. tasks.getByName("testClasses").dependsOn(this)
  64. tasks.getByName("compileTestKotlin").dependsOn(this)
  65. }
  66. generateBuildConfig() // somehow "generateBuildConfig" won't execute
  67. fun generateBuildConfig() {
  68. val text = """
  69. package net.mamoe.mirai.deps.test
  70. /**
  71. * This file was generated by Gradle task `generateBuildConfig`.
  72. */
  73. object BuildConfig {
  74. /**
  75. * Kotlin version used to compile mirai-core
  76. */
  77. const val kotlinVersion = "${Versions.kotlinCompiler}"
  78. }
  79. """.trimIndent() + "\n"
  80. val file = project.projectDir.resolve("test/BuildConfig.kt")
  81. if (!file.exists() || file.readText() != text) {
  82. file.writeText(text)
  83. }
  84. }
  85. /**
  86. * Kind note: To run this task you probably need a lot of host memory and luck.
  87. *
  88. * **If you see errors, don't panic, that's most probably not your fault.**
  89. *
  90. * Try:
  91. *
  92. * ```shell
  93. * ./gradlew :mirai-deps-test:updateProjectVersionForLocalDepsTest
  94. * ./gradlew clean :mirai-deps-test:publishMiraiArtifactsToMavenLocal "-Porg.gradle.parallel=false"
  95. * ```
  96. * Note this will change your project version in `buildSrc/src/main/kotlin/Versions.kt`. Be careful to change it back before committing!
  97. * Note also this is **extremely slow**. If your computer isn't good enough it may take hours.
  98. */
  99. val publishMiraiLocalArtifacts = tasks.register("publishMiraiLocalArtifacts", Exec::class) {
  100. group = "mirai"
  101. description = "Starts a child process to publish v$DEPS_TEST_VERSION artifacts to MavenLocal"
  102. workingDir(rootProject.projectDir)
  103. environment("mirai.build.project.version", DEPS_TEST_VERSION)
  104. commandLine(
  105. "./gradlew",
  106. "clean",
  107. publishMiraiArtifactsToMavenLocal.name,
  108. "--no-daemon",
  109. "--stacktrace",
  110. "--scan",
  111. "-Pkotlin.compiler.execution.strategy=in-process"
  112. )
  113. standardOutput = System.out
  114. errorOutput = System.err
  115. }
  116. version = Versions.core