build.gradle.kts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. id("com.gradle.plugin-publish")
  14. groovy
  15. id("java")
  16. //signing
  17. `maven-publish`
  18. }
  19. val integTest = sourceSets.create("integTest")
  20. /**
  21. * Because we use [compileOnly] for `kotlin-gradle-plugin`, it would be missing
  22. * in `plugin-under-test-metadata.properties`. Here we inject the jar into TestKit plugin
  23. * classpath via [PluginUnderTestMetadata] to avoid [NoClassDefFoundError].
  24. */
  25. val kotlinVersionForIntegrationTest: Configuration by configurations.creating
  26. dependencies {
  27. compileOnly(gradleApi())
  28. compileOnly(gradleKotlinDsl())
  29. compileOnly(kotlin("gradle-plugin-api"))
  30. compileOnly(kotlin("gradle-plugin"))
  31. compileOnly(kotlin("stdlib"))
  32. implementation("com.google.code.gson:gson:2.8.6")
  33. api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
  34. api(`jetbrains-annotations`)
  35. // override vulnerable Log4J version
  36. // https://blog.gradle.org/log4j-vulnerability
  37. implementation(`log4j-api`)
  38. implementation(`log4j-core`)
  39. testApi(kotlin("test-junit5"))
  40. testApi(`junit-jupiter-api`)
  41. testApi(`junit-jupiter-params`)
  42. "integTestApi"(kotlin("test-junit5"))
  43. "integTestApi"(`junit-jupiter-api`)
  44. "integTestApi"(`junit-jupiter-params`)
  45. "integTestImplementation"(`junit-jupiter-engine`)
  46. "integTestImplementation"(gradleTestKit())
  47. kotlinVersionForIntegrationTest(kotlin("gradle-plugin", "1.5.21"))
  48. }
  49. tasks.named<PluginUnderTestMetadata>("pluginUnderTestMetadata") {
  50. pluginClasspath.from(kotlinVersionForIntegrationTest)
  51. }
  52. version = Versions.console
  53. description = "Gradle plugin for Mirai Console"
  54. kotlin {
  55. explicitApi()
  56. }
  57. pluginBundle {
  58. website = "https://github.com/mamoe/mirai"
  59. vcsUrl = "https://github.com/mamoe/mirai"
  60. tags = listOf("framework", "kotlin", "mirai")
  61. }
  62. gradlePlugin {
  63. testSourceSets(integTest)
  64. plugins {
  65. create("miraiConsole") {
  66. id = "net.mamoe.mirai-console"
  67. displayName = "Mirai Console"
  68. description = project.description
  69. implementationClass = "net.mamoe.mirai.console.gradle.MiraiConsoleGradlePlugin"
  70. }
  71. }
  72. }
  73. val integrationTestTask = tasks.register<Test>("integTest") {
  74. description = "Runs the integration tests."
  75. group = "verification"
  76. testClassesDirs = integTest.output.classesDirs
  77. classpath = integTest.runtimeClasspath
  78. mustRunAfter(tasks.test)
  79. }
  80. tasks.check {
  81. dependsOn(integrationTestTask)
  82. }
  83. tasks {
  84. val generateBuildConstants by registering {
  85. group = "mirai"
  86. doLast {
  87. projectDir.resolve("src/main/kotlin/VersionConstants.kt").apply { createNewFile() }
  88. .writeText(
  89. projectDir.resolve("src/main/kotlin/VersionConstants.kt.template").readText()
  90. .replace("$\$CONSOLE_VERSION$$", Versions.console)
  91. .replace("$\$CORE_VERSION$$", Versions.core)
  92. )
  93. }
  94. }
  95. afterEvaluate {
  96. getByName("compileKotlin").dependsOn(generateBuildConstants)
  97. }
  98. }
  99. if (System.getenv("MIRAI_IS_SNAPSHOTS_PUBLISHING")?.toBoolean() == true) {
  100. configurePublishing("mirai-console-gradle", skipPublicationSetup = true)
  101. }