build.gradle.kts 5.1 KB

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