build.gradle.kts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import org.gradle.api.file.DuplicatesStrategy.EXCLUDE
  2. import java.text.SimpleDateFormat
  3. import java.util.Date
  4. buildscript {
  5. repositories {
  6. maven("https://repo.spongepowered.org/maven")
  7. }
  8. }
  9. plugins {
  10. `java-library`
  11. idea
  12. id("org.spongepowered.gradle.vanilla") version "0.2.1-SNAPSHOT"
  13. }
  14. idea {
  15. module {
  16. excludeDirs.add(project.file("run"))
  17. }
  18. }
  19. val modId: String by project
  20. val modName: String by project
  21. val modAuthor: String by project
  22. val modVersion: String by project
  23. val minecraftVersion: String by project
  24. val mixinVersion: String by project
  25. repositories {
  26. maven("https://repo.spongepowered.org/maven")
  27. mavenCentral()
  28. }
  29. dependencies {
  30. implementation("org.spongepowered:mixin:$mixinVersion")
  31. api("com.google.code.findbugs:jsr305:3.0.2")
  32. }
  33. base {
  34. archivesName.set("${modName.replace(" ", "")}-Common-$minecraftVersion")
  35. }
  36. minecraft {
  37. version(minecraftVersion)
  38. runs.clear()
  39. }
  40. allprojects {
  41. group = "com.$modAuthor.$modId"
  42. version = modVersion
  43. apply(plugin = "java")
  44. dependencies {
  45. implementation("org.jetbrains:annotations:22.0.0")
  46. }
  47. extensions.getByType<JavaPluginExtension>().apply {
  48. toolchain.languageVersion.set(JavaLanguageVersion.of(16))
  49. }
  50. tasks.withType<JavaCompile> {
  51. options.encoding = "UTF-8"
  52. options.release.set(16)
  53. }
  54. }
  55. subprojects {
  56. repositories {
  57. maven("https://repo.spongepowered.org/maven")
  58. }
  59. dependencies {
  60. implementation(rootProject)
  61. }
  62. base {
  63. archivesName.set("${modName.replace(" ", "")}-${project.name}-$minecraftVersion")
  64. }
  65. tasks.withType<JavaCompile> {
  66. source({ rootProject.sourceSets.main.get().allSource })
  67. }
  68. tasks.processResources {
  69. from(rootProject.sourceSets.main.get().resources)
  70. inputs.property("name", modName)
  71. inputs.property("version", modVersion)
  72. }
  73. tasks.jar {
  74. from(rootProject.file("LICENSE"))
  75. manifest {
  76. attributes(
  77. "Specification-Title" to modName,
  78. "Specification-Vendor" to modAuthor,
  79. "Specification-Version" to "1",
  80. "Implementation-Title" to "$modName-${project.name}",
  81. "Implementation-Version" to modVersion,
  82. "Implementation-Vendor" to modAuthor,
  83. "Implementation-Timestamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()),
  84. "MixinConfigs" to "$modId.mixin.json"
  85. )
  86. }
  87. }
  88. }
  89. val copyJars = tasks.register<Copy>("copyJars") {
  90. duplicatesStrategy = EXCLUDE
  91. for (subproject in subprojects) {
  92. dependsOn(subproject.tasks.build)
  93. from(subproject.base.libsDirectory.file("${subproject.base.archivesName.get()}-$modVersion.jar"))
  94. }
  95. into(file("${project.buildDir}/dist"))
  96. }
  97. tasks.build {
  98. finalizedBy(copyJars)
  99. }