build.gradle 6.9 KB

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