build.gradle 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. plugins {
  2. id 'fabric-loom' version '0.4.3'
  3. id 'maven-publish'
  4. id 'java'
  5. id 'java-library'
  6. id 'net.minecrell.licenser' version '0.4.1'
  7. id 'com.matthewprenger.cursegradle' version '1.4.0'
  8. id 'net.corda.plugins.jar-filter' version "5.0.8" apply false
  9. }
  10. import net.fabricmc.loom.task.RemapJarTask
  11. import java.text.SimpleDateFormat
  12. sourceCompatibility = targetCompatibility = 1.8
  13. archivesBaseName = "RoughlyEnoughItems"
  14. group = "me.shedaniel"
  15. def forceVersion = ""
  16. version = forceVersion != "" ? forceVersion : project.mod_version
  17. def includeDep = true
  18. minecraft {
  19. accessWidener = file("src/main/resources/rei.aw")
  20. }
  21. license {
  22. header rootProject.file('HEADER')
  23. include '**/*.java'
  24. }
  25. repositories {
  26. }
  27. jar {
  28. from "LICENSE"
  29. }
  30. processResources {
  31. filesMatching('fabric.mod.json') {
  32. expand 'version': project.version
  33. }
  34. inputs.property "version", project.version
  35. }
  36. dependencies {
  37. minecraft("com.mojang:minecraft:${project.minecraft_version}")
  38. mappings("net.fabricmc:yarn:${project.yarn_version}:v2")
  39. modApi("net.fabricmc:fabric-loader:${project.fabricloader_version}")
  40. modApi("net.fabricmc.fabric-api:fabric-api:${project.fabric_api}")
  41. modApi("me.shedaniel.cloth:cloth-events:${cloth_events_version}") {
  42. transitive = false
  43. }
  44. modApi("me.shedaniel.cloth:config-2:${cloth_config_version}") {
  45. exclude module: "fabric-api"
  46. }
  47. modApi("me.sargunvohra.mcmods:autoconfig1u:${project.autoconfig1u}") {
  48. exclude module: "fabric-api"
  49. }
  50. modApi("org.jetbrains:annotations:18.0.0")
  51. modCompileOnly("io.github.prospector:modmenu:${modmenu_version}") {
  52. transitive = false
  53. }
  54. modRuntime("io.github.prospector:modmenu:${modmenu_version}") {
  55. transitive = false
  56. }
  57. if (includeDep) {
  58. afterEvaluate {
  59. def listAdded = new ArrayList(Arrays.asList((api_exculde as String).split(',')))
  60. def eachDep = { dep ->
  61. for (apiIncludeDepStr in (api_include as String).split(',')) {
  62. if (apiIncludeDepStr.isEmpty()) continue
  63. def apiIncludeGroup = apiIncludeDepStr.split(':')[0]
  64. def apiIncludeDep = apiIncludeDepStr.split(':')[1]
  65. if (dep.module.id.group == apiIncludeGroup && dep.module.id.name.startsWith(apiIncludeDep)) {
  66. def version = dep.module.id.version.indexOf('@') >= 0 ? dep.module.id.version.substring(0, dep.module.id.version.indexOf('@')) : dep.module.id.version
  67. def mavenDep = "${dep.module.id.group}:${dep.module.id.name}:$version"
  68. if (!(mavenDep in listAdded)) {
  69. include(mavenDep) {
  70. transitive = false
  71. }
  72. listAdded.add(mavenDep)
  73. }
  74. break
  75. }
  76. }
  77. }
  78. configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each eachDep
  79. configurations.runtimeClasspath.resolvedConfiguration.firstLevelModuleDependencies.each eachDep
  80. }
  81. }
  82. }
  83. task jarFilter(type: net.corda.gradle.jarfilter.JarFilterTask) {
  84. jars remapJar
  85. annotations {
  86. forRemove = [
  87. "org.jetbrains.annotations.NotNull",
  88. "org.jetbrains.annotations.Nullable",
  89. "org.jetbrains.annotations.ApiStatus\$Experimental",
  90. "org.jetbrains.annotations.ApiStatus\$Internal",
  91. "org.jetbrains.annotations.ApiStatus\$ScheduledForRemoval",
  92. "org.jetbrains.annotations.ApiStatus\$AvailableSince",
  93. "org.jetbrains.annotations.ApiStatus\$NonExtendable",
  94. "org.jetbrains.annotations.ApiStatus\$OverrideOnly"
  95. ]
  96. }
  97. }
  98. task copyJarFilter(type: Copy) {
  99. from jarFilter
  100. into "${project.buildDir}/filtered-libs/"
  101. rename { "${project.archivesBaseName}-${project.version}.jar" }
  102. }
  103. task sourcesJar(type: Jar, dependsOn: classes) {
  104. classifier("sources")
  105. from sourceSets.main.allSource
  106. }
  107. task remapMavenJar(type: RemapJarTask, dependsOn: jar) {
  108. // classifier = "maven"
  109. afterEvaluate {
  110. //noinspection GroovyAccessibility
  111. input = file("${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar")
  112. archiveName = "${archivesBaseName}-${version}.jar"
  113. //noinspection GroovyAccessibility
  114. addNestedDependencies = false
  115. }
  116. }
  117. def releaseChangelog = "No changelog"
  118. /* Thank you modmenu & fablabs */
  119. task releaseOnCf {
  120. def df = new SimpleDateFormat("yyyy-MM-dd HH:mm")
  121. df.setTimeZone(TimeZone.getTimeZone("UTC"))
  122. def branch
  123. if (System.env.BRANCH_NAME) {
  124. branch = System.env.BRANCH_NAME
  125. branch = branch.substring(branch.lastIndexOf("/") + 1)
  126. } else {
  127. branch = "git rev-parse --abbrev-ref HEAD".execute().in.text.trim()
  128. }
  129. if (branch == "HEAD") {
  130. branch = "git rev-parse --short HEAD".execute().in.text.trim()
  131. }
  132. def time = df.format(new Date())
  133. def changes = new StringBuilder()
  134. changes << "<h2>REI v$project.version for $project.supported_version</h2>Updated at <b>$time</b>.<br><a href=\"https://www.github.com/shedaniel/RoughlyEnoughItems/commits/$branch\">Click here for changelog</a>"
  135. def proc = "git log --max-count=200 --pretty=format:%s".execute()
  136. proc.in.eachLine { line ->
  137. def processedLine = line.toString()
  138. if (!processedLine.contains("New translations") && !processedLine.contains("Merge") && !processedLine.contains("branch")) {
  139. changes << "<br>- ${processedLine.capitalize()}"
  140. }
  141. }
  142. proc.waitFor()
  143. releaseChangelog = changes.toString()
  144. dependsOn tasks.getByName("curseforge")
  145. }
  146. curseforge {
  147. if (project.hasProperty('danielshe_curse_api_key') || System.getenv('danielshe_curse_api_key') != null) {
  148. apiKey = project.hasProperty('danielshe_curse_api_key') ? project.property('danielshe_curse_api_key') : System.getenv('danielshe_curse_api_key')
  149. project {
  150. id = '310111'
  151. releaseType = 'beta'
  152. changelogType = "html"
  153. changelog = releaseChangelog
  154. addGameVersion '1.16-Snapshot'
  155. addGameVersion 'Java 8'
  156. addGameVersion 'Fabric'
  157. relations {
  158. requiredDependency 'fabric-api'
  159. embeddedLibrary 'cloth'
  160. embeddedLibrary 'cloth-config'
  161. }
  162. mainArtifact(file("${project.buildDir}/filtered-libs/${project.archivesBaseName}-${project.version}.jar")) {
  163. displayName = "[Fabric $project.supported_version] v$project.version"
  164. }
  165. addArtifact(file("${project.buildDir}/libs/${project.archivesBaseName}-${project.version}-sources.jar")) {
  166. displayName = "[Fabric $project.supported_version] v$project.version Sources"
  167. }
  168. afterEvaluate {
  169. uploadTask.dependsOn("copyJarFilter")
  170. }
  171. }
  172. }
  173. options {
  174. forgeGradleIntegration = false
  175. javaVersionAutoDetect = false
  176. }
  177. }
  178. publishing {
  179. publications {
  180. mavenJava(MavenPublication) {
  181. artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}.jar")) {
  182. builtBy remapMavenJar
  183. }
  184. artifact(sourcesJar) {
  185. builtBy remapSourcesJar
  186. }
  187. }
  188. }
  189. repositories {
  190. if (project.hasProperty('danielshe_pass')) {
  191. maven {
  192. url = "http://deploy.modmuss50.me/"
  193. credentials {
  194. username = "danielshe"
  195. password = project.getProperty('danielshe_pass')
  196. }
  197. }
  198. }
  199. }
  200. }