build.gradle.kts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. @file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE")
  2. import java.time.Duration
  3. import java.util.*
  4. import kotlin.math.pow
  5. buildscript {
  6. repositories {
  7. mavenLocal()
  8. maven(url = "https://mirrors.huaweicloud.com/repository/maven")
  9. maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
  10. jcenter()
  11. google()
  12. }
  13. dependencies {
  14. classpath("com.github.jengelman.gradle.plugins:shadow:5.2.0")
  15. classpath("com.android.tools.build:gradle:${Versions.Android.androidGradlePlugin}")
  16. classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.stdlib}")
  17. classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.Kotlin.stdlib}")
  18. classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.Kotlin.atomicFU}")
  19. }
  20. }
  21. plugins {
  22. id("org.jetbrains.dokka") version Versions.Kotlin.dokka apply false
  23. // id("com.jfrog.bintray") version Versions.Publishing.bintray apply false
  24. }
  25. runCatching {
  26. val keyProps = Properties().apply {
  27. file("local.properties").takeIf { it.exists() }?.inputStream()?.use { load(it) }
  28. }
  29. if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) {
  30. project.ext.set("isAndroidSDKAvailable", true)
  31. } else {
  32. project.ext.set("isAndroidSDKAvailable", false)
  33. }
  34. }
  35. allprojects {
  36. group = "net.mamoe"
  37. version = Versions.Mirai.version
  38. repositories {
  39. maven(url = "https://mirrors.huaweicloud.com/repository/maven")
  40. maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
  41. jcenter()
  42. google()
  43. }
  44. }
  45. subprojects {
  46. afterEvaluate {
  47. apply(plugin = "com.github.johnrengelman.shadow")
  48. val kotlin =
  49. (this as ExtensionAware).extensions.getByName("kotlin") as? org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
  50. ?: return@afterEvaluate
  51. val shadowJvmJar by tasks.creating(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) {
  52. group = "mirai"
  53. val compilation =
  54. kotlin.targets.first { it.platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm }.compilations["main"]
  55. dependsOn(compilation.compileKotlinTask)
  56. configurations = mutableListOf(compilation.compileDependencyFiles as Configuration)
  57. this.exclude { file ->
  58. file.name.endsWith(".sf", ignoreCase = true)
  59. .also { if (it) println("excluded ${file.name}") }
  60. }
  61. }
  62. val githubUpload by tasks.creating {
  63. group = "mirai"
  64. dependsOn(shadowJvmJar)
  65. doFirst {
  66. timeout.set(Duration.ofMinutes(10))
  67. File(projectDir, "build/libs").walk()
  68. .filter { it.isFile }
  69. .onEach { println("all files=$it") }
  70. .filter { it.name.matches(Regex("""${project.name}-([0-9]|\.)*\.jar""")) }
  71. .onEach { println("matched file: ${it.name}") }
  72. .associateBy { it.nameWithoutExtension.substringAfterLast('-') }
  73. .onEach { println("versions: $it") }
  74. .maxBy {
  75. it.key.split('.').foldRightIndexed(0) { index: Int, s: String, acc: Int ->
  76. acc + 100.0.pow(2 - index).toInt() * (s.toIntOrNull() ?: 0)
  77. }
  78. }?.let { (_, file) ->
  79. val filename = file.name
  80. println("Uploading file $filename")
  81. runCatching {
  82. upload.GitHub.upload(
  83. file,
  84. "https://api.github.com/repos/mamoe/mirai-repo/contents/shadow/${project.name}/$filename",
  85. project
  86. )
  87. }.exceptionOrNull()?.let {
  88. System.err.println("Upload failed")
  89. it.printStackTrace() // force show stacktrace
  90. throw it
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }