build.gradle.kts 5.5 KB

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