build.gradle.kts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. @file:Suppress("UnusedImport")
  2. plugins {
  3. kotlin("jvm")
  4. kotlin("kapt")
  5. id("java-gradle-plugin")
  6. id("com.gradle.plugin-publish")
  7. id("java")
  8. //signing
  9. `maven-publish`
  10. id("com.jfrog.bintray")
  11. id("com.github.johnrengelman.shadow")
  12. }
  13. dependencies {
  14. compileOnly(gradleApi())
  15. compileOnly(kotlin("gradle-plugin-api").toString()) {
  16. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  17. }
  18. compileOnly(kotlin("gradle-plugin").toString()) {
  19. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  20. }
  21. compileOnly(kotlin("stdlib"))
  22. api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
  23. api("org.jetbrains:annotations:19.0.0")
  24. }
  25. dependencies {
  26. testApi(kotlin("test"))
  27. testApi(kotlin("test-junit5"))
  28. testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0")
  29. testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0")
  30. }
  31. version = Versions.console
  32. description = "Gradle plugin for Mirai Console"
  33. pluginBundle {
  34. website = "https://github.com/mamoe/mirai-console"
  35. vcsUrl = "https://github.com/mamoe/mirai-console"
  36. tags = listOf("framework", "kotlin", "mirai")
  37. }
  38. gradlePlugin {
  39. plugins {
  40. create("miraiConsole") {
  41. id = "net.mamoe.mirai-console"
  42. displayName = "Mirai Console"
  43. description = project.description
  44. implementationClass = "net.mamoe.mirai.console.gradle.MiraiConsoleGradlePlugin"
  45. }
  46. }
  47. }
  48. kotlin {
  49. sourceSets.all {
  50. target.compilations.all {
  51. kotlinOptions {
  52. apiVersion = "1.3"
  53. languageVersion = "1.3"
  54. jvmTarget = "1.8"
  55. freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=all"
  56. }
  57. }
  58. languageSettings.apply {
  59. progressiveMode = true
  60. useExperimentalAnnotation("kotlin.RequiresOptIn")
  61. useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
  62. useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
  63. useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
  64. }
  65. }
  66. }
  67. tasks {
  68. "test"(Test::class) {
  69. useJUnitPlatform()
  70. }
  71. val compileKotlin by getting {}
  72. @Suppress("UNUSED_VARIABLE")
  73. val fillBuildConstants by registering {
  74. group = "mirai"
  75. doLast {
  76. (compileKotlin as org.jetbrains.kotlin.gradle.tasks.KotlinCompile).source.filter { it.name == "VersionConstants.kt" }.single()
  77. .let { file ->
  78. file.writeText(
  79. file.readText()
  80. .replace(
  81. Regex("""const val CONSOLE_VERSION = ".*"""")
  82. ) {
  83. """const val CONSOLE_VERSION = "${Versions.console}""""
  84. }
  85. .replace(
  86. Regex("""const val CORE_VERSION = ".*"""")
  87. ) { """const val CORE_VERSION = "${Versions.core}"""" }
  88. )
  89. }
  90. }
  91. }
  92. compileKotlin.dependsOn(fillBuildConstants)
  93. }
  94. java {
  95. sourceCompatibility = JavaVersion.VERSION_1_8
  96. targetCompatibility = JavaVersion.VERSION_1_8
  97. }
  98. tasks.withType(JavaCompile::class.java) {
  99. options.encoding = "UTF8"
  100. }
  101. // setupPublishing("mirai-console-gradle")