build.gradle 7.8 KB

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