build.gradle.kts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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("signing")
  16. id("me.him188.kotlin-jvm-blocking-bridge")
  17. `maven-publish`
  18. }
  19. description = "Mirai API module"
  20. kotlin {
  21. explicitApi()
  22. if (isAndroidSDKAvailable) {
  23. // apply(from = rootProject.file("gradle/android.gradle"))
  24. // android("android") {
  25. // publishAllLibraryVariants()
  26. // }
  27. jvm("android") {
  28. attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
  29. // publishAllLibraryVariants()
  30. }
  31. } else {
  32. printAndroidNotInstalled()
  33. }
  34. jvm("common") {
  35. attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
  36. }
  37. jvm("jvm")
  38. // jvm("android") {
  39. // attributes.attribute(Attribute.of("mirai.target.platform", String::class.java), "android")
  40. // }
  41. sourceSets {
  42. val commonMain by getting {
  43. dependencies {
  44. api(kotlin("reflect"))
  45. api(`kotlinx-serialization-core-jvm`)
  46. api(`kotlinx-serialization-json-jvm`)
  47. api(`kotlinx-coroutines-core-jvm`) // don't remove it, otherwise IDE will complain
  48. api(`kotlinx-coroutines-jdk8`)
  49. api(`ktor-client-okhttp`)
  50. implementation(project(":mirai-core-utils"))
  51. implementation(`kotlinx-serialization-protobuf-jvm`)
  52. implementation(`jetbrains-annotations`)
  53. implementation(`log4j-api`)
  54. implementation(`kotlinx-atomicfu-jvm`)
  55. implementationKotlinxIoJvm()
  56. compileOnly(`slf4j-api`)
  57. }
  58. }
  59. commonTest {
  60. dependencies {
  61. runtimeOnly(`log4j-core`)
  62. }
  63. }
  64. if (isAndroidSDKAvailable) {
  65. val androidMain by getting {
  66. dependsOn(commonMain)
  67. dependencies {
  68. compileOnly(`android-runtime`)
  69. // api(`ktor-client-android`)
  70. }
  71. }
  72. }
  73. val jvmMain by getting {
  74. }
  75. val jvmTest by getting {
  76. dependencies {
  77. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  78. }
  79. }
  80. }
  81. }
  82. if (isAndroidSDKAvailable) {
  83. tasks.register("checkAndroidApiLevel") {
  84. doFirst {
  85. analyzes.AndroidApiLevelCheck.check(
  86. buildDir.resolve("classes/kotlin/android/main"),
  87. project.property("mirai.android.target.api.level")!!.toString().toInt(),
  88. project
  89. )
  90. }
  91. group = "verification"
  92. this.mustRunAfter("androidMainClasses")
  93. }
  94. tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
  95. }
  96. configureMppPublishing()
  97. afterEvaluate {
  98. project(":binary-compatibility-validator").tasks["apiBuild"].dependsOn(project(":mirai-core-api").tasks["build"])
  99. project(":binary-compatibility-validator-android").tasks["apiBuild"].dependsOn(project(":mirai-core-api").tasks["build"])
  100. }