build.gradle.kts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. @file:Suppress("UNUSED_VARIABLE")
  2. plugins {
  3. kotlin("multiplatform")
  4. id("kotlinx-atomicfu")
  5. id("kotlinx-serialization")
  6. `maven-publish`
  7. id("com.jfrog.bintray") version "1.8.4-jetbrains-3" // DO NOT CHANGE THIS VERSION UNLESS YOU WANT TO WASTE YOUR TIME
  8. }
  9. apply(from = rootProject.file("gradle/publish.gradle"))
  10. val kotlinVersion: String by rootProject.ext
  11. val atomicFuVersion: String by rootProject.ext
  12. val coroutinesVersion: String by rootProject.ext
  13. val kotlinXIoVersion: String by rootProject.ext
  14. val coroutinesIoVersion: String by rootProject.ext
  15. val klockVersion: String by rootProject.ext
  16. val ktorVersion: String by rootProject.ext
  17. val serializationVersion: String by rootProject.ext
  18. fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
  19. fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
  20. description = "QQ protocol library"
  21. version = rootProject.ext.get("mirai_version")!!.toString()
  22. val isAndroidSDKAvailable: Boolean by project
  23. kotlin {
  24. if (isAndroidSDKAvailable) {
  25. apply(from = rootProject.file("gradle/android.gradle"))
  26. android("android") {
  27. publishAllLibraryVariants()
  28. }
  29. } else {
  30. println(
  31. """Android SDK 可能未安装.
  32. $name 的 Android 目标编译将不会进行.
  33. 这不会影响 Android 以外的平台的编译.
  34. """.trimIndent()
  35. )
  36. println(
  37. """Android SDK might not be installed.
  38. Android target of $name will not be compiled.
  39. It does no influence on the compilation of other platforms.
  40. """.trimIndent()
  41. )
  42. }
  43. jvm("jvm") {
  44. }
  45. sourceSets {
  46. all {
  47. languageSettings.enableLanguageFeature("InlineClasses")
  48. languageSettings.useExperimentalAnnotation("kotlin.Experimental")
  49. dependencies {
  50. api(project(":mirai-core"))
  51. api(kotlin("stdlib", kotlinVersion))
  52. api("org.jetbrains.kotlinx:atomicfu:$atomicFuVersion")
  53. api(kotlinx("io", kotlinXIoVersion))
  54. api(kotlinx("coroutines-io", coroutinesIoVersion))
  55. api(kotlinx("coroutines-core", coroutinesVersion))
  56. }
  57. }
  58. commonMain {
  59. dependencies {
  60. api(kotlinx("serialization-runtime-common", serializationVersion))
  61. }
  62. }
  63. commonTest {
  64. dependencies {
  65. api(kotlin("test-annotations-common"))
  66. api(kotlin("test-common"))
  67. implementation(kotlin("script-runtime"))
  68. }
  69. }
  70. if (isAndroidSDKAvailable) {
  71. val androidMain by getting {
  72. dependencies {
  73. }
  74. }
  75. val androidTest by getting {
  76. dependencies {
  77. implementation(kotlin("test", kotlinVersion))
  78. implementation(kotlin("test-junit", kotlinVersion))
  79. implementation(kotlin("test-annotations-common"))
  80. implementation(kotlin("test-common"))
  81. }
  82. }
  83. }
  84. val jvmMain by getting {
  85. dependencies {
  86. runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE
  87. api(kotlinx("serialization-runtime", serializationVersion))
  88. }
  89. }
  90. val jvmTest by getting {
  91. dependencies {
  92. api(kotlin("test", kotlinVersion))
  93. api(kotlin("test-junit", kotlinVersion))
  94. implementation("org.pcap4j:pcap4j-distribution:1.8.2")
  95. runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE
  96. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  97. }
  98. }
  99. }
  100. }