build.gradle.kts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 shadow.relocateImplementation
  11. plugins {
  12. id("com.android.library")
  13. kotlin("multiplatform")
  14. kotlin("plugin.serialization")
  15. id("kotlinx-atomicfu")
  16. id("me.him188.kotlin-jvm-blocking-bridge")
  17. // id("me.him188.maven-central-publish")
  18. `maven-publish`
  19. }
  20. description = "mirai-core utilities"
  21. kotlin {
  22. explicitApi()
  23. apply(plugin = "explicit-api")
  24. configureJvmTargetsHierarchical()
  25. configureNativeTargetsHierarchical(project)
  26. sourceSets {
  27. val commonMain by getting {
  28. dependencies {
  29. api(kotlin("reflect"))
  30. api(`kotlinx-serialization-core`)
  31. api(`kotlinx-serialization-json`)
  32. api(`kotlinx-coroutines-core`)
  33. implementation(`kotlinx-serialization-protobuf`)
  34. relocateImplementation(`ktor-io_relocated`)
  35. }
  36. }
  37. configure(NATIVE_TARGETS.map { getByName(it + "Main") }
  38. + NATIVE_TARGETS.map { getByName(it + "Test") }) {
  39. dependencies {
  40. // no relocation in native
  41. implementation(`ktor-io`) {
  42. exclude(ExcludeProperties.`slf4j-api`)
  43. }
  44. }
  45. }
  46. val commonTest by getting {
  47. dependencies {
  48. api(yamlkt)
  49. implementation(`kotlinx-coroutines-test`)
  50. }
  51. }
  52. findByName("jvmBaseMain")?.apply {
  53. dependencies {
  54. implementation(`jetbrains-annotations`)
  55. }
  56. }
  57. findByName("jvmMain")?.apply {
  58. }
  59. findByName("jvmTest")?.apply {
  60. dependencies {
  61. implementation(`kotlinx-coroutines-debug`)
  62. runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
  63. }
  64. }
  65. findByName("nativeMain")?.apply {
  66. dependencies {
  67. // implementation("com.soywiz.korlibs.krypto:krypto:2.4.12") // ':mirai-core-utils:compileNativeMainKotlinMetadata' fails because compiler cannot find reference
  68. }
  69. }
  70. }
  71. }
  72. if (tasks.findByName("androidMainClasses") != null) {
  73. tasks.register("checkAndroidApiLevel") {
  74. doFirst {
  75. analyzes.AndroidApiLevelCheck.check(
  76. buildDir.resolve("classes/kotlin/android/main"),
  77. project.property("mirai.android.target.api.level")!!.toString().toInt(),
  78. project
  79. )
  80. }
  81. group = "verification"
  82. this.mustRunAfter("androidMainClasses")
  83. }
  84. tasks.getByName("androidBaseTest").dependsOn("checkAndroidApiLevel")
  85. }
  86. configureMppPublishing()
  87. //mavenCentralPublish {
  88. // artifactId = "mirai-core-utils"
  89. // githubProject("mamoe", "mirai")
  90. // developer("Mamoe Technologies", email = "[email protected]", url = "https://github.com/mamoe")
  91. // licenseFromGitHubProject("AGPLv3", "dev")
  92. // publishPlatformArtifactsInRootModule = "jvm"
  93. //}
  94. android {
  95. namespace = "net.mamoe.mirai.utils"
  96. }