build.gradle.kts 3.7 KB

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