2
0

build.gradle.kts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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("gradle-plugin-api"))
  18. implementation(kotlin("gradle-plugin"))
  19. implementation(kotlin("stdlib"))
  20. api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
  21. api(`jetbrains-annotations`)
  22. testImplementation(kotlin("test-junit5"))
  23. testImplementation(`junit-jupiter-api`)
  24. testImplementation(`junit-jupiter-params`)
  25. testRuntimeOnly(`junit-jupiter-engine`)
  26. }
  27. tasks.getByName("test", Test::class) {
  28. environment("mirai.root.project.dir", rootProject.projectDir.absolutePath)
  29. }
  30. val publishMiraiArtifactsToMavenLocal by tasks.registering {
  31. group = "mirai"
  32. description = "Publish all mirai artifacts to MavenLocal"
  33. val publishTasks = rootProject.allprojects.mapNotNull { proj ->
  34. proj.tasks.findByName("publishToMavenLocal")
  35. }
  36. dependsOn(publishTasks)
  37. doLast {
  38. // delete shadowed Jars, since Kotlin can't compile modules that depend on them.
  39. rootProject.subprojects
  40. .asSequence()
  41. .flatMap { proj -> proj.tasks.filter { task -> task.name.contains("relocate") } }
  42. .flatMap { it.outputs.files }
  43. .filter { it.isFile && it.name.endsWith(".jar") }
  44. .forEach { it.delete() }
  45. }
  46. }
  47. tasks.register("generateBuildConfig") {
  48. group = "mirai"
  49. doLast {
  50. generateBuildConfig()
  51. }
  52. tasks.getByName("testClasses").dependsOn(this)
  53. tasks.getByName("compileTestKotlin").dependsOn(this)
  54. }
  55. generateBuildConfig() // somehow "generateBuildConfig" won't execute
  56. fun generateBuildConfig() {
  57. val text = """
  58. package net.mamoe.mirai.deps.test
  59. /**
  60. * This file was generated by Gradle task `generateBuildConfig`.
  61. */
  62. object BuildConfig {
  63. /**
  64. * Kotlin version used to compile mirai-core
  65. */
  66. const val kotlinVersion = "${Versions.kotlinCompiler}"
  67. }
  68. """.trimIndent() + "\n"
  69. val file = project.projectDir.resolve("test/BuildConfig.kt")
  70. if (!file.exists() || file.readText() != text) {
  71. file.writeText(text)
  72. }
  73. }
  74. tasks.register("publishMiraiLocalArtifacts", Exec::class) {
  75. group = "mirai"
  76. description = "Starts a child process to publish v2.99.0-deps-test artifacts to MavenLocal"
  77. workingDir(rootProject.projectDir)
  78. environment("mirai.build.project.version", "2.99.0-deps-test")
  79. commandLine(
  80. "./gradlew",
  81. publishMiraiArtifactsToMavenLocal.name,
  82. "--no-daemon",
  83. "-Pkotlin.compiler.execution.strategy=in-process"
  84. )
  85. standardOutput = System.out
  86. errorOutput = System.err
  87. }
  88. version = Versions.core