2
0

build.gradle.kts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 compilations =
  54. kotlin.targets.filter { it.platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm }
  55. .map { it.compilations["main"] }
  56. compilations.forEach {
  57. dependsOn(it.compileKotlinTask)
  58. }
  59. compilations.forEach {
  60. from(it.output)
  61. }
  62. configurations = compilations.map { it.compileDependencyFiles as Configuration }
  63. this.exclude { file ->
  64. file.name.endsWith(".sf", ignoreCase = true)
  65. .also { if (it) println("excluded ${file.name}") }
  66. }
  67. }
  68. val githubUpload by tasks.creating {
  69. group = "mirai"
  70. dependsOn(shadowJvmJar)
  71. doFirst {
  72. timeout.set(Duration.ofMinutes(10))
  73. File(projectDir, "build/libs").walk()
  74. .filter { it.isFile }
  75. .onEach { println("all files=$it") }
  76. .filter { it.name.matches(Regex("""${project.name}-([0-9]|\.)*\.jar""")) }
  77. .onEach { println("matched file: ${it.name}") }
  78. .associateBy { it.nameWithoutExtension.substringAfterLast('-') }
  79. .onEach { println("versions: $it") }
  80. .maxBy {
  81. it.key.split('.').foldRightIndexed(0) { index: Int, s: String, acc: Int ->
  82. acc + 100.0.pow(2 - index).toInt() * (s.toIntOrNull() ?: 0)
  83. }
  84. }?.let { (_, file) ->
  85. val filename = file.name
  86. println("Uploading file $filename")
  87. runCatching {
  88. upload.GitHub.upload(
  89. file,
  90. "https://api.github.com/repos/mamoe/mirai-repo/contents/shadow/${project.name}/$filename",
  91. project
  92. )
  93. }.exceptionOrNull()?.let {
  94. System.err.println("Upload failed")
  95. it.printStackTrace() // force show stacktrace
  96. throw it
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }