build.gradle 6.7 KB

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