build.gradle.kts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright 2019-2023 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/dev/LICENSE
  8. */
  9. @file:Suppress("UNUSED_VARIABLE")
  10. import BinaryCompatibilityConfigurator.configureBinaryValidators
  11. import shadow.relocateCompileOnly
  12. import shadow.relocateImplementation
  13. plugins {
  14. kotlin("multiplatform")
  15. id("kotlinx-atomicfu")
  16. kotlin("plugin.serialization")
  17. id("me.him188.kotlin-jvm-blocking-bridge")
  18. id("me.him188.kotlin-dynamic-delegation")
  19. // id("me.him188.maven-central-publish")
  20. `maven-publish`
  21. }
  22. description = "Mirai Protocol implementation for QQ Android"
  23. kotlin {
  24. explicitApi()
  25. apply(plugin = "explicit-api")
  26. configureJvmTargetsHierarchical("net.mamoe.mirai.internal")
  27. optInForAllSourceSets("net.mamoe.mirai.utils.MiraiExperimentalApi")
  28. optInForAllSourceSets("net.mamoe.mirai.utils.MiraiInternalApi")
  29. optInForAllSourceSets("net.mamoe.mirai.LowLevelApi")
  30. optInForAllSourceSets("kotlinx.serialization.ExperimentalSerializationApi")
  31. sourceSets.apply {
  32. val commonMain by getting {
  33. dependencies {
  34. api(project(":mirai-core-api"))
  35. api(`kotlinx-serialization-core`)
  36. api(`kotlinx-serialization-json`)
  37. api(`kotlinx-coroutines-core`)
  38. implementation(`kt-bignum`)
  39. implementation(project(":mirai-core-utils"))
  40. implementation(`kotlinx-serialization-protobuf`)
  41. implementation(`kotlinx-atomicfu`)
  42. // runtime from mirai-core-utils
  43. relocateCompileOnly(`ktor-io_relocated`)
  44. // relocateImplementation(`ktor-http_relocated`)
  45. // relocateImplementation(`ktor-serialization_relocated`)
  46. // relocateImplementation(`ktor-websocket-serialization_relocated`)
  47. }
  48. }
  49. commonTest {
  50. dependencies {
  51. implementation(kotlin("script-runtime"))
  52. implementation(`kotlinx-coroutines-test`)
  53. api(yamlkt)
  54. }
  55. }
  56. findByName("jvmBaseMain")?.apply {
  57. dependencies {
  58. implementation(`log4j-api`)
  59. implementation(`netty-handler`)
  60. api(`kotlinx-coroutines-jdk8`) // use -jvm modules for this magic target 'jvmBase'
  61. }
  62. }
  63. findByName("jvmBaseTest")?.apply {
  64. dependencies {
  65. implementation(`kotlinx-coroutines-debug`)
  66. }
  67. }
  68. findByName("androidMain")?.apply {
  69. dependencies {
  70. if (rootProject.property("mirai.android.target.api.level")!!.toString().toInt() < 23) {
  71. // Ship with BC if we are targeting 23 or lower where AndroidKeyStore is not stable enough.
  72. // For more info, read `net.mamoe.mirai.internal.utils.crypto.EcdhAndroidKt.create` in `androidMain`.
  73. implementation(bouncycastle)
  74. }
  75. }
  76. }
  77. // For Android with JDK
  78. findByName("androidTest")?.apply {
  79. dependencies {
  80. implementation(bouncycastle)
  81. }
  82. }
  83. // For Android with SDK
  84. findByName("androidUnitTest")?.apply {
  85. dependencies {
  86. implementation(bouncycastle)
  87. }
  88. }
  89. findByName("jvmMain")?.apply {
  90. dependencies {
  91. implementation(bouncycastle)
  92. // api(kotlinx("coroutines-debug", Versions.coroutines))
  93. }
  94. }
  95. findByName("jvmTest")?.apply {
  96. dependencies {
  97. api(`kotlinx-coroutines-debug`)
  98. // implementation("net.mamoe:mirai-login-solver-selenium:1.0-dev-14")
  99. }
  100. }
  101. // Kt bignum
  102. findByName("jvmBaseMain")?.apply {
  103. dependencies {
  104. relocateImplementation(`kt-bignum_relocated`)
  105. }
  106. }
  107. // Ktor
  108. findByName("commonMain")?.apply {
  109. dependencies {
  110. compileOnly(`ktor-io`)
  111. implementation(`ktor-client-core`)
  112. }
  113. }
  114. findByName("jvmBaseMain")?.apply {
  115. // relocate for JVM like modules
  116. dependencies {
  117. relocateCompileOnly(`ktor-io_relocated`) // runtime from mirai-core-utils
  118. relocateImplementation(`ktor-client-core_relocated`)
  119. }
  120. }
  121. findByName("jvmBaseMain")?.apply {
  122. dependencies {
  123. relocateImplementation(`ktor-client-okhttp_relocated`)
  124. }
  125. }
  126. }
  127. }
  128. atomicfu {
  129. transformJvm = false
  130. }
  131. if (tasks.findByName("androidMainClasses") != null) {
  132. tasks.register("checkAndroidApiLevel") {
  133. doFirst {
  134. analyzes.AndroidApiLevelCheck.check(
  135. buildDir.resolve("classes/kotlin/android/main"),
  136. project.property("mirai.android.target.api.level")!!.toString().toInt(),
  137. project
  138. )
  139. }
  140. group = "verification"
  141. this.mustRunAfter("androidMainClasses")
  142. }
  143. tasks.findByName("androidTest")?.dependsOn("checkAndroidApiLevel")
  144. }
  145. configureMppPublishing()
  146. configureBinaryValidators(setOf("jvm", "android").filterTargets())
  147. //mavenCentralPublish {
  148. // artifactId = "mirai-core"
  149. // githubProject("mamoe", "mirai")
  150. // developer("Mamoe Technologies", email = "[email protected]", url = "https://github.com/mamoe")
  151. // licenseFromGitHubProject("AGPLv3", "dev")
  152. // publishPlatformArtifactsInRootModule = "jvm"
  153. //}