2
0

build.gradle.kts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/master/LICENSE
  8. */
  9. @file:Suppress("UNUSED_VARIABLE")
  10. import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
  11. plugins {
  12. kotlin("multiplatform")
  13. kotlin("plugin.serialization")
  14. id("kotlinx-atomicfu")
  15. id("net.mamoe.kotlin-jvm-blocking-bridge")
  16. `maven-publish`
  17. id("com.jfrog.bintray")
  18. }
  19. description = "mirai-core utilities"
  20. val isAndroidSDKAvailable: Boolean by project
  21. kotlin {
  22. explicitApi()
  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("common") {
  43. attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
  44. }
  45. jvm("jvm")
  46. // jvm("android") {
  47. // attributes.attribute(Attribute.of("mirai.target.platform", String::class.java), "android")
  48. // }
  49. sourceSets {
  50. val commonMain by getting {
  51. dependencies {
  52. api(kotlin("serialization"))
  53. api(kotlin("reflect"))
  54. api1(`kotlinx-serialization-core`)
  55. api1(`kotlinx-serialization-json`)
  56. implementation1(`kotlinx-serialization-protobuf`)
  57. api1(`kotlinx-io-jvm`)
  58. api1(`kotlinx-coroutines-io-jvm`)
  59. api(`kotlinx-coroutines-core`)
  60. implementation1(`kotlinx-atomicfu`)
  61. api1(`ktor-client-core`)
  62. api1(`ktor-network`)
  63. }
  64. }
  65. if (isAndroidSDKAvailable) {
  66. androidMain {
  67. dependencies {
  68. api1(`ktor-client-android`)
  69. }
  70. }
  71. }
  72. val jvmMain by getting
  73. val jvmTest by getting {
  74. dependencies {
  75. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  76. }
  77. }
  78. }
  79. }
  80. fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) =
  81. implementation(dependencyNotation) {
  82. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  83. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
  84. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
  85. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
  86. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
  87. }
  88. fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.api1(dependencyNotation: String) =
  89. api(dependencyNotation) {
  90. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  91. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
  92. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
  93. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
  94. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
  95. }
  96. configureMppPublishing()