2
0

build.gradle.kts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. id("com.jfrog.bintray")
  19. }
  20. description = "Mirai API module"
  21. kotlin {
  22. explicitApi()
  23. if (isAndroidSDKAvailable) {
  24. // apply(from = rootProject.file("gradle/android.gradle"))
  25. // android("android") {
  26. // publishAllLibraryVariants()
  27. // }
  28. jvm("android") {
  29. attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
  30. // publishAllLibraryVariants()
  31. }
  32. } else {
  33. printAndroidNotInstalled()
  34. }
  35. jvm("common") {
  36. attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
  37. }
  38. jvm("jvm")
  39. // jvm("android") {
  40. // attributes.attribute(Attribute.of("mirai.target.platform", String::class.java), "android")
  41. // }
  42. sourceSets {
  43. val commonMain by getting {
  44. dependencies {
  45. implementation(project(":mirai-core-utils"))
  46. api(kotlin("serialization"))
  47. api(kotlin("reflect"))
  48. api(`kotlinx-serialization-core`)
  49. api(`kotlinx-serialization-json`)
  50. implementation(`kotlinx-serialization-protobuf`)
  51. api(`kotlinx-coroutines-core`)
  52. implementation(`jetbrains-annotations`)
  53. // api(`kotlinx-coroutines-jdk8`)
  54. api(`ktor-client-okhttp`)
  55. api(`ktor-client-core`)
  56. api(`ktor-network`)
  57. compileOnly(`log4j-api`)
  58. compileOnly(slf4j)
  59. // they use Kotlin 1.3 so we need to ignore transitive dependencies
  60. api1(`kotlinx-io-jvm`)
  61. api1(`kotlinx-coroutines-io-jvm`)
  62. implementation1(`kotlinx-atomicfu`)
  63. }
  64. }
  65. if (isAndroidSDKAvailable) {
  66. val androidMain by getting {
  67. dependsOn(commonMain)
  68. dependencies {
  69. compileOnly(`android-runtime`)
  70. api1(`ktor-client-android`)
  71. }
  72. }
  73. }
  74. val jvmMain by getting {
  75. }
  76. val jvmTest by getting {
  77. dependencies {
  78. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  79. }
  80. }
  81. }
  82. }
  83. tasks.register("checkAndroidApiLevel") {
  84. doFirst {
  85. androidutil.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. fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) =
  96. implementation(dependencyNotation) {
  97. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  98. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
  99. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
  100. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
  101. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
  102. }
  103. fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.api1(dependencyNotation: String) =
  104. api(dependencyNotation) {
  105. exclude("org.jetbrains.kotlin", "kotlin-stdlib")
  106. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
  107. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
  108. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
  109. exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
  110. }
  111. configureMppPublishing()
  112. afterEvaluate {
  113. project(":binary-compatibility-validator").tasks["apiBuild"].dependsOn(project(":mirai-core-api").tasks["build"])
  114. project(":binary-compatibility-validator-android").tasks["apiBuild"].dependsOn(project(":mirai-core-api").tasks["build"])
  115. }