build.gradle.kts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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("net.mamoe.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-jdk8`)
  48. api(`ktor-client-okhttp`)
  49. implementation(project(":mirai-core-utils"))
  50. implementation(`kotlinx-serialization-protobuf-jvm`)
  51. implementation(`jetbrains-annotations`)
  52. implementation(`log4j-api`)
  53. implementation(`kotlinx-atomicfu-jvm`)
  54. implementationKotlinxIoJvm()
  55. compileOnly(`slf4j-api`)
  56. }
  57. }
  58. commonTest {
  59. dependencies {
  60. runtimeOnly(`log4j-core`)
  61. }
  62. }
  63. if (isAndroidSDKAvailable) {
  64. val androidMain by getting {
  65. dependsOn(commonMain)
  66. dependencies {
  67. compileOnly(`android-runtime`)
  68. // api(`ktor-client-android`)
  69. }
  70. }
  71. }
  72. val jvmMain by getting {
  73. }
  74. val jvmTest by getting {
  75. dependencies {
  76. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  77. }
  78. }
  79. }
  80. }
  81. if (isAndroidSDKAvailable) {
  82. tasks.register("checkAndroidApiLevel") {
  83. doFirst {
  84. analyzes.AndroidApiLevelCheck.check(
  85. buildDir.resolve("classes/kotlin/android/main"),
  86. project.property("mirai.android.target.api.level")!!.toString().toInt(),
  87. project
  88. )
  89. }
  90. group = "verification"
  91. this.mustRunAfter("androidMainClasses")
  92. }
  93. tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
  94. }
  95. configureMppPublishing()
  96. afterEvaluate {
  97. project(":binary-compatibility-validator").tasks["apiBuild"].dependsOn(project(":mirai-core-api").tasks["build"])
  98. project(":binary-compatibility-validator-android").tasks["apiBuild"].dependsOn(project(":mirai-core-api").tasks["build"])
  99. }