build.gradle 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import groovy.json.JsonOutput
  2. buildscript {
  3. repositories {
  4. maven {
  5. url = 'https://files.minecraftforge.net/maven'
  6. }
  7. jcenter()
  8. mavenCentral()
  9. }
  10. dependencies {
  11. classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
  12. }
  13. }
  14. plugins {
  15. id "com.matthewprenger.cursegradle" version "1.4.0"
  16. }
  17. apply plugin: 'net.minecraftforge.gradle'
  18. apply plugin: 'eclipse'
  19. apply plugin: 'maven-publish'
  20. apply from: 'https://raw.githubusercontent.com/MinecraftModDevelopment/Gradle-Collection/22e7d543a18cd30675277fbfa3669e3d9e206010/generic/secrets.gradle'
  21. import groovy.json.JsonOutput
  22. if (project.hasProperty('secretFile')) {
  23. loadSecrets(new File((String) findProperty('secretFile')))
  24. }
  25. version = '7.0.0'
  26. if (System.getenv('BUILD_NUMBER') != null) {
  27. version += "." + System.getenv('BUILD_NUMBER')
  28. }
  29. group = 'com.blamejared.controlling'
  30. archivesBaseName = 'Controlling'
  31. sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
  32. repositories {
  33. maven {
  34. url 'https://dogforce-games.com/maven'
  35. }
  36. }
  37. minecraft {
  38. mappings channel: 'snapshot', version: '20200820-1.16.1'
  39. accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
  40. runs {
  41. client {
  42. workingDirectory project.file('run')
  43. property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
  44. property 'forge.logging.console.level', 'debug'
  45. mods {
  46. examplemod {
  47. source sourceSets.main
  48. }
  49. }
  50. }
  51. server {
  52. workingDirectory project.file('run')
  53. property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
  54. property 'forge.logging.console.level', 'debug'
  55. mods {
  56. examplemod {
  57. source sourceSets.main
  58. }
  59. }
  60. }
  61. }
  62. }
  63. task genGitChangelog() {
  64. def stdout = new ByteArrayOutputStream()
  65. // first commit to check from, in our case the first commit of the branch
  66. String firstCommit = "efff217f353e51ce43751caf94b1924818b710e8";
  67. String repoLink = "https://github.com/jaredlll08/Controlling/commit/"
  68. // was having issues with grep and spaces in the regex
  69. exec {
  70. commandLine 'git', 'log', '-i', '--grep=version\\spush', '--grep=open\\sbeta\\sspecific\\scode', '--pretty=tformat:%H', '--date=local', firstCommit + '..@{0}'
  71. standardOutput = stdout
  72. }
  73. if (stdout.toString().trim().indexOf("\n") >= 0) {
  74. firstCommit = stdout.toString().split("\n")[0].trim();
  75. }
  76. System.out.println("Last version hash: \"" + firstCommit + "\"");
  77. stdout = new ByteArrayOutputStream()
  78. def test = exec {
  79. commandLine 'git', 'log', '--pretty=tformat:- [%s](' + repoLink + '%H) - %aN - %cd', '--max-parents=1', '--date=local', firstCommit + "..@"
  80. standardOutput = stdout
  81. }
  82. File file = new File("changelog.md")
  83. file.write("### Current version: " + project.version)
  84. file.append("\n" + stdout.toString())
  85. System.out.println("Changelog generated!")
  86. }
  87. dependencies {
  88. minecraft 'net.minecraftforge:forge:1.16.3-34.0.5'
  89. }
  90. jar {
  91. manifest {
  92. attributes([
  93. "Specification-Title" : "controlling",
  94. "Specification-Vendor" : "BlameJared",
  95. "Specification-Version" : "1",
  96. "Implementation-Title" : project.name,
  97. "Implementation-Version" : "${version}",
  98. "Implementation-Vendor" : "controlling",
  99. "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")],)
  100. }
  101. }
  102. task sourcesJar(type: Jar, dependsOn: classes) {
  103. description = 'Creates a JAR containing the source code.'
  104. from sourceSets.main.allSource
  105. classifier = 'sources'
  106. }
  107. task javadocJar(type: Jar, dependsOn: javadoc) {
  108. description = 'Creates a JAR containing the JavaDocs.'
  109. from javadoc.destinationDir
  110. classifier = 'javadoc'
  111. }
  112. task deobfJar(type: Jar) {
  113. description = 'Creates a JAR containing the non-obfuscated compiled code.'
  114. from sourceSets.main.output
  115. classifier = "deobf"
  116. }
  117. artifacts {
  118. archives sourcesJar
  119. archives javadocJar
  120. archives deobfJar
  121. }
  122. publishing {
  123. publications {
  124. mavenJava(MavenPublication) {
  125. groupId project.group
  126. artifactId project.archivesBaseName
  127. version project.version
  128. from components.java
  129. // Allows the maven pom file to be modified.
  130. pom.withXml {
  131. // Go through all the dependencies.
  132. asNode().dependencies.dependency.each { dep ->
  133. println 'Surpressing artifact ' + dep.artifactId.last().value().last() + ' from maven dependencies.'
  134. assert dep.parent().remove(dep)
  135. }
  136. }
  137. artifact sourcesJar {
  138. classifier 'sources'
  139. }
  140. artifact javadocJar {
  141. classifier 'javadoc'
  142. }
  143. artifact deobfJar {
  144. classifier 'deobf'
  145. }
  146. }
  147. }
  148. repositories {
  149. maven {
  150. url "file://" + System.getenv("local_maven")
  151. }
  152. }
  153. }
  154. curseforge {
  155. apiKey = findProperty('curseforge_api_token') ?: 0
  156. project {
  157. id = "250398"
  158. releaseType = 'release'
  159. changelog = file("changelog.md")
  160. changelogType = 'markdown'
  161. // addArtifact(sourcesJar)
  162. // addArtifact(javadocJar)
  163. addArtifact(deobfJar)
  164. }
  165. }
  166. task updateVersionTracker {
  167. onlyIf {
  168. project.hasProperty('versionTrackerAPI')
  169. }
  170. doLast {
  171. def body = [
  172. 'author' : "${project.findProperty('versionTrackerAuthor')}",
  173. 'projectName' : "controlling",
  174. 'gameVersion' : "1.16.3",
  175. 'projectVersion': "${version}",
  176. 'homepage' : "${project.findProperty('versionTrackerHomepage')}",
  177. 'uid' : "${project.findProperty('versionTrackerKey')}"
  178. ]
  179. // Opens a connection to the version tracker API and writes the payload JSON.
  180. def req = new URL(project.findProperty('versionTrackerAPI')).openConnection()
  181. req.setRequestMethod('POST')
  182. req.setRequestProperty('Content-Type', 'application/json; charset=UTF-8')
  183. req.setRequestProperty('User-Agent', "CraftTweaker Tracker Gradle")
  184. req.setDoOutput(true)
  185. req.getOutputStream().write(JsonOutput.toJson(body).getBytes("UTF-8"))
  186. // We need to attempt a read in order to actually send the message.
  187. println "VersionCheck Status code: ${req.getResponseCode()}"
  188. println "VersionCheck Response: ${req.getInputStream().getText()}"
  189. }
  190. }