build.gradle.kts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
  2. import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
  3. /*
  4. * Declares the version of the Gradle wrapper. We need 4.9 for now because
  5. * ForgeGradle 3+ is a hard dependency for Gradle 4.9, 4.10 is not compatible
  6. */
  7. val wrapper by tasks.getting(Wrapper::class) {
  8. gradleVersion = "4.9"
  9. }
  10. /*
  11. * Sets up project references to be used in child scripts, like
  12. * ":bukkit", ":core", ":sponge" where these projects need to be
  13. * referred to for dependencies, paths, outputs etc.
  14. * Projects is specifically an object stored in <root>/buildSrc/src/main/java/Config.kt
  15. * It's a nullable variable, but we just store it here and use it elsewhere.
  16. */
  17. Projects.core = project("core")
  18. Projects.bukkit = project("bukkit")
  19. Projects.sponge = project("sponge")
  20. /*
  21. Declares the various other projects and stores them to Gradle's `extra` properties.
  22. These are potentially usable for other purposes, but for now, they're here only to
  23. declare the values for this root project's dependency (for shadowjar)
  24. */
  25. var core: Project by extra { project("core") }
  26. val bukkit by extra { project("bukkit") }
  27. val bukkit_18 by extra { bukkit.project("1_8_8") }
  28. val bukkit_112 by extra { bukkit.project("1_12") }
  29. val bukkit_113 by extra { bukkit.project("1_13") }
  30. val sponge by extra { project("sponge") }
  31. val sponge_7 by extra { sponge.project("api7") }
  32. group = properties["pluginGroup"]!!
  33. version = properties["pluginVersion"]!!
  34. /*
  35. Even though all projects declares some of these plugins, we want to declare them the traditional
  36. way so that we can have IDE utiliziation and processing, it helps with writing these scripts.
  37. */
  38. plugins {
  39. `java-library`
  40. `maven-publish`
  41. id("com.github.johnrengelman.shadow") version "4.0.4"
  42. }
  43. /*
  44. Default management for ALL projects, not just root, or ":bukkit", but all projects and
  45. their children projects.
  46. */
  47. allprojects {
  48. /*
  49. We need the java library processing, and shadow allows us to run
  50. shadowJar to relocate dependencies and bundle dependencies into a fat jar.
  51. */
  52. apply(plugin="java-library")
  53. apply(plugin="com.github.johnrengelman.shadow")
  54. /*
  55. Defines all the repositories for all project dependency resolutions. Some of these
  56. repositories are meant for specific dependencies, so the content filters will
  57. prevent attempts at resolving those dependencies being requested at those repositories.
  58. Constants are defined in <root>/buildSrc/src/main/java/Config.kt
  59. */
  60. repositories {
  61. mavenCentral()
  62. maven(Repos.sk89q) // WorldEdit/WorldGuard
  63. maven(Repos.bstats) // bstats
  64. maven(Repos.sponge) // Sponge, Configurate, and some other things
  65. maven(Repos.spigot) // Spigot and Bukkit
  66. maven(Repos.sonatype) // General Maven
  67. mavenLocal() // For nms packages
  68. }
  69. // Sets all projects compatibility level to Java 8
  70. java {
  71. sourceCompatibility = JavaVersion.VERSION_1_8
  72. targetCompatibility = JavaVersion.VERSION_1_8
  73. }
  74. // Encoding for all packages is UTF-8
  75. tasks.getting(JavaCompile::class) {
  76. options.encoding = "UTF-8"
  77. }
  78. // Default shadow jar configuration. Sub projects will override and add on,
  79. // but this sets up at the very least the jdbc connection dependencies to be relocated
  80. val shadowJar by tasks.getting(ShadowJar::class) { // Configure basics of relocation
  81. relocate(Shadow.Origin.juli, Shadow.Target.juli)
  82. relocate(Shadow.Origin.tomcat, Shadow.Target.tomcat)
  83. exclude(Shadow.Exclude.ForgeGradle.dummyThing)
  84. exclude(Shadow.Exclude.ForgeGradle.template)
  85. }
  86. }
  87. /*
  88. All subprojects shadowjar tasks that will exclude various dependencies, while
  89. the root project will include some of these dependencies (like jdbc, configurate)
  90. so that the sub project jars are already somewhat minimized, in the event those
  91. platform jars are to be deployed individually versus an overall "all platforms"
  92. jar.
  93. */
  94. subprojects {
  95. val shadowJar by tasks.getting(ShadowJar::class) {
  96. dependencies {
  97. exclude(dependency("${Deps.Groups.sponge}:${Deps.Modules.configurate_yaml}"))
  98. exclude(dependency(Shadow.Exclude.guava))
  99. exclude(dependency(Shadow.Exclude.snakeyaml))
  100. exclude(dependency(Shadow.Exclude.tomcat))
  101. exclude(dependency(Shadow.Exclude.juli))
  102. }
  103. }
  104. }
  105. // Sets up this root project to depend on all the implementations supported.
  106. // By default, they all already should have shadow relocations and packaging,
  107. // and their dependencies should not be leaking into this project.
  108. dependencies {
  109. compile(bukkit)
  110. compile(sponge)
  111. compile(bukkit_18)
  112. compile(bukkit_112)
  113. compile(bukkit_113)
  114. compile(sponge_7)
  115. }
  116. // Configure shadow for the root project, we want to relocate bstats-bukkit
  117. // and whatever else is configured in the allProjects configuration
  118. val shadowJar by tasks.getting(ShadowJar::class) { // Root shadow relocation
  119. relocate(Shadow.Origin.bstatsBukkit, Shadow.Target.bstatsBukkit)
  120. baseName = "mcMMO"
  121. classifier = "bundle"
  122. }
  123. // Tell the build task to depend on shadowjar.
  124. val build by tasks
  125. build.dependsOn(shadowJar)