2
0

build.gradle.kts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. afterEvaluate {
  22. tasks.getByName("compileKotlinCommon").enabled = false
  23. tasks.getByName("compileTestKotlinCommon").enabled = false
  24. tasks.getByName("compileCommonMainKotlinMetadata").enabled = false
  25. tasks.getByName("compileKotlinMetadata").enabled = false
  26. }
  27. kotlin {
  28. explicitApi()
  29. if (isAndroidSDKAvailable) {
  30. apply(from = rootProject.file("gradle/android.gradle"))
  31. android("android") {
  32. publishAllLibraryVariants()
  33. }
  34. } else {
  35. println(
  36. """Android SDK 可能未安装.
  37. $name 的 Android 目标编译将不会进行.
  38. 这不会影响 Android 以外的平台的编译.
  39. """.trimIndent()
  40. )
  41. println(
  42. """Android SDK might not be installed.
  43. Android target of $name will not be compiled.
  44. It does no influence on the compilation of other platforms.
  45. """.trimIndent()
  46. )
  47. }
  48. jvm("common") {
  49. attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
  50. }
  51. jvm("jvm")
  52. // jvm("android") {
  53. // attributes.attribute(Attribute.of("mirai.target.platform", String::class.java), "android")
  54. // }
  55. sourceSets {
  56. val commonMain by getting {
  57. dependencies {
  58. api(kotlin("serialization"))
  59. api(kotlin("reflect"))
  60. api1(`kotlinx-serialization-core`)
  61. api1(`kotlinx-serialization-json`)
  62. implementation1(`kotlinx-serialization-protobuf`)
  63. api1(`kotlinx-io-jvm`)
  64. api1(`kotlinx-coroutines-io-jvm`)
  65. api(`kotlinx-coroutines-core`)
  66. implementation1(`kotlinx-atomicfu`)
  67. api1(`ktor-client-core`)
  68. api1(`ktor-network`)
  69. }
  70. }
  71. if (isAndroidSDKAvailable) {
  72. androidMain {
  73. dependencies {
  74. api1(`ktor-client-android`)
  75. }
  76. }
  77. }
  78. val jvmMain by getting
  79. val jvmTest by getting {
  80. dependencies {
  81. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  82. }
  83. }
  84. }
  85. }
  86. fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) =
  87. implementation(dependencyNotation) {
  88. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  89. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
  90. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
  91. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
  92. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
  93. }
  94. fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.api1(dependencyNotation: String) =
  95. api(dependencyNotation) {
  96. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  97. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
  98. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
  99. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
  100. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
  101. }
  102. configureMppPublishing()