build.gradle.kts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2019-2020 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("UnusedImport")
  10. import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
  11. buildscript {
  12. dependencies {
  13. classpath("com.guardsquare:proguard-gradle:${Versions.proguard}")
  14. }
  15. }
  16. plugins {
  17. kotlin("jvm")
  18. kotlin("plugin.serialization")
  19. `maven-publish`
  20. id("com.jfrog.bintray")
  21. id("net.mamoe.kotlin-jvm-blocking-bridge")
  22. }
  23. version = Versions.project
  24. description = "Mirai core shadowed"
  25. dependencies {
  26. api(project(":mirai-core"))
  27. api(project(":mirai-core-api"))
  28. api(project(":mirai-core-utils"))
  29. }
  30. configurePublishing("mirai-core-all")
  31. afterEvaluate {
  32. tasks.register<proguard.gradle.ProGuardTask>("proguard") {
  33. group = "mirai"
  34. verbose()
  35. injars(tasks.getByName<ShadowJar>("shadowJar"))
  36. kotlin.runCatching {
  37. file("build/libs/${project.name}-${project.version}-all-min.jar").delete()
  38. }.exceptionOrNull()?.printStackTrace()
  39. outjars("build/libs/${project.name}-${project.version}-all-min.jar")
  40. val kotlinLibraries = kotlin.target.compilations["main"].compileDependencyFiles
  41. // .plus(kotlin.target.compilations["main"].runtimeDependencyFiles)
  42. kotlinLibraries.distinctBy { it.normalize().name }.forEach { file ->
  43. if (file.name.contains("-common")) return@forEach
  44. if (file.name.contains("-metadata")) return@forEach
  45. if (file.extension == "jar") libraryjars(file)
  46. }
  47. val javaHome = System.getProperty("java.home")
  48. // Automatically handle the Java version of this build.
  49. if (System.getProperty("java.version").startsWith("1.")) {
  50. // Before Java 9, the runtime classes were packaged in a single jar file.
  51. libraryjars("$javaHome/lib/rt.jar")
  52. } else {
  53. File(javaHome, "jmods").listFiles().orEmpty().forEach { file ->
  54. libraryjars(
  55. mapOf(
  56. "jarfilter" to "!**.jar",
  57. "filter" to "!module-info.class"
  58. ), file
  59. )
  60. }
  61. // // As of Java 9, the runtime classes are packaged in modular jmod files.
  62. // libraryjars(
  63. // // filters must be specified first, as a map
  64. // mapOf("jarfilter" to "!**.jar",
  65. // "filter" to "!module-info.class"),
  66. // "$javaHome/jmods/java.base.jmod"
  67. // )
  68. }
  69. configuration("mirai.pro")
  70. configuration("kotlinx-serialization.pro")
  71. dontobfuscate()
  72. // keepattributes("*Annotation*,synthetic")
  73. }
  74. }