build.gradle.kts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import com.blamejared.modtemplate.Utils
  2. import com.diluv.schoomp.Webhook
  3. import com.diluv.schoomp.message.Message
  4. import com.diluv.schoomp.message.embed.Embed
  5. import java.io.IOException
  6. import java.text.SimpleDateFormat
  7. import java.util.*
  8. buildscript {
  9. repositories {
  10. mavenCentral()
  11. }
  12. dependencies {
  13. classpath("com.diluv.schoomp:Schoomp:1.2.5")
  14. }
  15. }
  16. plugins {
  17. `java-library`
  18. idea
  19. id("com.blamejared.modtemplate") version ("3.0.0.37")
  20. }
  21. val minecraftVersion: String by project
  22. val modName: String by project
  23. val modAuthor: String by project
  24. val modJavaVersion: String by project
  25. val modAvatar: String by project
  26. val modVersion: String by project
  27. val gitRepo: String by project
  28. version = Utils.updatingSemVersion(modVersion)
  29. subprojects {
  30. apply(plugin = "java")
  31. extensions.configure<JavaPluginExtension> {
  32. toolchain.languageVersion.set(JavaLanguageVersion.of(modJavaVersion))
  33. withJavadocJar()
  34. withSourcesJar()
  35. }
  36. tasks.withType<JavaCompile> {
  37. options.encoding = "UTF-8"
  38. options.release.set(modJavaVersion.toInt())
  39. }
  40. tasks {
  41. jar {
  42. manifest {
  43. attributes(
  44. "Specification-Title" to modName,
  45. "Specification-Vendor" to modAuthor,
  46. "Specification-Version" to archiveVersion,
  47. "Implementation-Title" to project.name,
  48. "Implementation-Version" to archiveVersion,
  49. "Implementation-Vendor" to modAuthor,
  50. "Implementation-Timestamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()),
  51. "Timestamp" to System.currentTimeMillis(),
  52. "Built-On-Java" to "${System.getProperty("java.vm.version")} (${System.getProperty("java.vm.vendor")})",
  53. "Build-On-Minecraft" to minecraftVersion
  54. )
  55. }
  56. }
  57. }
  58. repositories {
  59. mavenCentral()
  60. maven("https://repo.spongepowered.org/repository/maven-public/") {
  61. name = "Sponge / Mixin"
  62. }
  63. maven("https://maven.blamejared.com") {
  64. name = "BlameJared Maven (CrT / Bookshelf)"
  65. }
  66. }
  67. dependencies {
  68. implementation("org.jetbrains:annotations:21.0.1")
  69. }
  70. tasks.withType<GenerateModuleMetadata>() {
  71. enabled = false
  72. }
  73. }
  74. tasks.create("postDiscord") {
  75. doLast {
  76. try {
  77. // Create a new webhook instance for Discord
  78. val webhook = Webhook(Utils.locateProperty(project, "discordCFWebhook"), "$modName CurseForge Gradle Upload")
  79. // Craft a message to send to Discord using the webhook.
  80. val message = Message()
  81. message.username = modName
  82. message.avatarUrl = modAvatar
  83. message.content = "$modName $version for Minecraft $minecraftVersion has been published!"
  84. val embed = Embed()
  85. val downloadSources = StringJoiner("\n")
  86. if (project(":Fabric").ext.has("curse_file_url")) {
  87. downloadSources.add("<:fabric:932163720568782878> [Fabric](${project(":Fabric").ext.get("curse_file_url")})")
  88. }
  89. if (project(":Forge").ext.has("curse_file_url")) {
  90. downloadSources.add("<:forge:932163698003443804> [Forge](${project(":Forge").ext.get("curse_file_url")})")
  91. }
  92. downloadSources.add(
  93. "<:maven:932165250738970634> `\"${project(":Common").group}:${project(":Common").base.archivesName.get()}:${
  94. project(":Common").version
  95. }\"`"
  96. )
  97. downloadSources.add(
  98. "<:maven:932165250738970634> `\"${project(":Fabric").group}:${project(":Fabric").base.archivesName.get()}:${
  99. project(":Fabric").version
  100. }\"`"
  101. )
  102. downloadSources.add(
  103. "<:maven:932165250738970634> `\"${project(":Forge").group}:${project(":Forge").base.archivesName.get()}:${
  104. project(":Forge").version
  105. }\"`"
  106. )
  107. // Add Curseforge DL link if available.
  108. val downloadString = downloadSources.toString()
  109. if (downloadString.isNotEmpty()) {
  110. embed.addField("Download", downloadString, false)
  111. }
  112. // Just use the Forge changelog for now, the files are the same anyway.
  113. embed.addField("Changelog", Utils.getCIChangelog(project, gitRepo).take(1000), false)
  114. embed.color = 0xF16436
  115. message.addEmbed(embed)
  116. webhook.sendMessage(message)
  117. } catch (e: IOException) {
  118. project.logger.error("Failed to push CF Discord webhook.")
  119. project.file("post_discord_error.log").writeText(e.stackTraceToString())
  120. }
  121. }
  122. }