build.gradle.kts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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"
  8. }
  9. val kotlinVersion: String by rootProject.ext
  10. val atomicFuVersion: String by rootProject.ext
  11. val coroutinesVersion: String by rootProject.ext
  12. val kotlinXIoVersion: String by rootProject.ext
  13. val coroutinesIoVersion: String by rootProject.ext
  14. val ktorVersion: String by rootProject.ext
  15. val serializationVersion: String by rootProject.ext
  16. fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
  17. fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
  18. description = "QQ protocol library"
  19. val isAndroidSDKAvailable: Boolean by project
  20. val miraiVersion: String by project
  21. version = miraiVersion
  22. kotlin {
  23. if (isAndroidSDKAvailable) {
  24. apply(from = rootProject.file("gradle/android.gradle"))
  25. android("android") {
  26. publishAllLibraryVariants()
  27. }
  28. } else {
  29. println(
  30. """Android SDK 可能未安装.
  31. $name 的 Android 目标编译将不会进行.
  32. 这不会影响 Android 以外的平台的编译.
  33. """.trimIndent()
  34. )
  35. println(
  36. """Android SDK might not be installed.
  37. Android target of $name will not be compiled.
  38. It does no influence on the compilation of other platforms.
  39. """.trimIndent()
  40. )
  41. }
  42. jvm()
  43. sourceSets {
  44. all {
  45. languageSettings.enableLanguageFeature("InlineClasses")
  46. languageSettings.useExperimentalAnnotation("kotlin.Experimental")
  47. }
  48. commonMain {
  49. dependencies {
  50. api(kotlin("stdlib", kotlinVersion))
  51. api(kotlin("serialization", kotlinVersion))
  52. api(kotlin("reflect", kotlinVersion))
  53. api(kotlinx("coroutines-core-common", coroutinesVersion))
  54. api(kotlinx("serialization-runtime-common", serializationVersion))
  55. api(kotlinx("serialization-protobuf-common", serializationVersion))
  56. api(kotlinx("io", kotlinXIoVersion))
  57. api(kotlinx("coroutines-io", coroutinesIoVersion))
  58. api(kotlinx("coroutines-core", coroutinesVersion))
  59. api("org.jetbrains.kotlinx:atomicfu-common:$atomicFuVersion")
  60. api(ktor("client-cio", ktorVersion))
  61. api(ktor("client-core", ktorVersion))
  62. api(ktor("network", ktorVersion))
  63. }
  64. }
  65. commonTest {
  66. dependencies {
  67. implementation(kotlin("test-annotations-common"))
  68. implementation(kotlin("test-common"))
  69. }
  70. }
  71. if (isAndroidSDKAvailable) {
  72. val androidMain by getting {
  73. dependencies {
  74. api(kotlin("reflect", kotlinVersion))
  75. api(kotlinx("io-jvm", kotlinXIoVersion))
  76. api(kotlinx("serialization-runtime", serializationVersion))
  77. api(kotlinx("serialization-protobuf", serializationVersion))
  78. api(kotlinx("coroutines-android", coroutinesVersion))
  79. api(kotlinx("coroutines-io-jvm", coroutinesIoVersion))
  80. api(ktor("client-android", ktorVersion))
  81. }
  82. }
  83. val androidTest by getting {
  84. dependencies {
  85. implementation(kotlin("test", kotlinVersion))
  86. implementation(kotlin("test-junit", kotlinVersion))
  87. implementation(kotlin("test-annotations-common"))
  88. implementation(kotlin("test-common"))
  89. }
  90. }
  91. }
  92. val jvmMain by getting {
  93. dependencies {
  94. //api(kotlin("stdlib-jdk8", kotlinVersion))
  95. //api(kotlin("stdlib-jdk7", kotlinVersion))
  96. api(kotlin("reflect", kotlinVersion))
  97. api(ktor("client-core-jvm", ktorVersion))
  98. api(kotlinx("io-jvm", kotlinXIoVersion))
  99. api(kotlinx("serialization-runtime", serializationVersion))
  100. api(kotlinx("serialization-protobuf", serializationVersion))
  101. api(kotlinx("coroutines-io-jvm", coroutinesIoVersion))
  102. api(kotlinx("coroutines-core", coroutinesVersion))
  103. api("org.bouncycastle:bcprov-jdk15on:1.64")
  104. runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE
  105. }
  106. }
  107. val jvmTest by getting {
  108. dependencies {
  109. implementation(kotlin("test", kotlinVersion))
  110. implementation(kotlin("test-junit", kotlinVersion))
  111. implementation("org.pcap4j:pcap4j-distribution:1.8.2")
  112. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  113. }
  114. }
  115. }
  116. }
  117. //
  118. //tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
  119. // kotlinOptions.jvmTarget = "1.8"
  120. //}
  121. apply(from = rootProject.file("gradle/publish.gradle"))