Advertisement
SergOmarov

build.gradle

Feb 17th, 2017
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.44 KB | None | 0 0
  1. import groovy.json.JsonSlurper
  2. import thermos.CreateChangelog
  3. import thermos.InstallBundle
  4. import thermos.VersionParser
  5.  
  6. buildscript {
  7. repositories {
  8.  
  9. maven {
  10.  
  11. name 'prok'
  12.  
  13. url 'https://repo.prok.pw/'
  14.  
  15. }
  16.  
  17. maven {
  18.  
  19. name 'forge'
  20.  
  21. url 'http://files.minecraftforge.net/maven'
  22.  
  23. }
  24.  
  25. maven {
  26.  
  27. name 'spigot'
  28.  
  29. url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
  30.  
  31. }
  32.  
  33. maven {
  34.  
  35. name 'maven2'
  36.  
  37. url 'http://repo1.maven.org/maven/'
  38.  
  39. }
  40.  
  41. mavenCentral()
  42.  
  43. mavenLocal()
  44.  
  45. }
  46. dependencies {
  47. // classpath files('FGS.jar')
  48. classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
  49. }
  50. }
  51.  
  52. tasks.whenTaskAdded {
  53. if (it.name.startsWith('publish')) it.dependsOn 'preparePublication'
  54. }
  55.  
  56. apply plugin: 'maven'
  57. apply plugin: 'cauldron'
  58. apply plugin: 'maven-publish'
  59. apply plugin: 'signing'
  60.  
  61. repositories {
  62. clear()
  63. maven {
  64. name 'prok'
  65. url 'https://repo.prok.pw/'
  66. }
  67. maven {
  68. name 'forge'
  69. url 'http://files.minecraftforge.net/maven'
  70. }
  71. maven {
  72. name 'minecraft'
  73. url 'https://libraries.minecraft.net/'
  74. }
  75. mavenCentral()
  76. }
  77.  
  78. minecraft {
  79. version = '1.7.10'
  80. mcpVersion = '9.05'
  81. mainClass = 'cpw.mods.fml.relauncher.ServerLaunchWrapper'
  82. tweakClass = 'cpw.mods.fml.common.launcher.FMLTweaker'
  83. installerVersion = "1.4"
  84. srgExtra "PK: org/bukkit/craftbukkit org/bukkit/craftbukkit/v1_7_R4"
  85. }
  86.  
  87. group = 'pw.prok'
  88.  
  89. ext.buildInfoCached = null;
  90.  
  91. def buildInfo(String key) {
  92. if (!buildInfoCached) {
  93. if (project.hasProperty('officialBuild')) {
  94. buildInfoCached = new JsonSlurper().parse(new URL("https://api.prok.pw/repo/version/${group}/${name}"))
  95. } else {
  96. buildInfoCached = [
  97. nextBuildNumber: 'UNOFFICIAL',
  98. version : 'NONE'
  99. ]
  100. }
  101. }
  102. return key ? buildInfoCached[key] : buildInfoCached;
  103. }
  104.  
  105. ext.gitInfoCached = null;
  106.  
  107. def gitInfo(String key) {
  108. if (!gitInfoCached) {
  109. if (file('.git').exists()) {
  110. gitInfoCached = [
  111. hash : ['git', 'log', "--format=%h", '-n', '1'].execute().text.trim(),
  112. fullHash: ['git', 'log', "--format=%H", '-n', '1'].execute().text.trim(),
  113. branch : System.getenv("CI_BUILD_REF_NAME") ?: ['git', 'symbolic-ref', '--short', 'HEAD'].execute().text.trim(),
  114. message : ['git', 'log', "--format=%B", '-n', '1'].execute().text.trim()
  115. ]
  116. } else {
  117. gitInfoCached = [
  118. hash : 'NOT_A_GIT',
  119. fullHash: 'NOT_A_GIT',
  120. branch : 'NOT_A_GIT',
  121. message : 'NOT_A_GIT'
  122. ]
  123. }
  124. }
  125. return key ? gitInfoCached[key] : gitInfoCached;
  126. }
  127.  
  128. ext.mcVersion = "1.7.10"
  129. ext.forgeVersion = VersionParser.parseForgeRevision(file('src/main/resources/fmlversion.properties'))
  130. ext.revision = project.hasProperty('revision') ? project.getProperty('revision') : buildInfo('nextBuildNumber')
  131. version = "${mcVersion}-${forgeVersion}.${revision}"
  132. if (project.hasProperty('officialBuild')) println "Updated KCauldron version: ${version}"
  133.  
  134. launch4j {
  135. jreMinVersion = '1.6.0'
  136. }
  137.  
  138. configurations {
  139. compile.extendsFrom exported
  140. libraries
  141. bootstrap
  142. }
  143.  
  144. dependencies {
  145. bootstrap 'pw.prok:KBootstrap:0.2.+'
  146. libraries 'net.minecraft:launchwrapper:1.12@jar'
  147. libraries 'org.ow2.asm:asm-all:5.0.3'
  148. libraries 'com.typesafe.akka:akka-actor_2.11:2.3.3'
  149. libraries 'com.typesafe:config:1.2.1'
  150. libraries 'org.scala-lang:scala-actors-migration_2.11:1.1.0'
  151. libraries 'org.scala-lang:scala-compiler:2.11.1'
  152. libraries 'org.scala-lang.plugins:scala-continuations-library_2.11:1.0.2'
  153. libraries 'org.scala-lang.plugins:scala-continuations-plugin_2.11.1:1.0.2'
  154. libraries 'org.scala-lang:scala-library:2.11.1'
  155. libraries 'org.scala-lang:scala-parser-combinators_2.11:1.0.1'
  156. libraries 'org.scala-lang:scala-reflect:2.11.1'
  157. libraries 'org.scala-lang:scala-swing_2.11:1.0.1'
  158. libraries 'org.scala-lang:scala-xml_2.11:1.0.2'
  159. libraries 'net.sf.jopt-simple:jopt-simple:4.7'
  160. libraries 'lzma:lzma:0.0.1'
  161. libraries 'org.yaml:snakeyaml:1.9'
  162. libraries 'commons-lang:commons-lang:2.6'
  163. libraries 'org.avaje:ebean:2.7.3'
  164. libraries 'jline:jline:2.6'
  165. libraries 'net.md-5:SpecialSource:1.7-SNAPSHOT'
  166. libraries 'net.sourceforge.argo:argo:2.25'
  167. libraries 'org.fusesource.jansi:jansi:1.8'
  168. libraries 'com.googlecode.json-simple:json-simple:1.1'
  169. libraries 'org.xerial:sqlite-jdbc:3.7.2'
  170. libraries 'mysql:mysql-connector-java:5.1.14'
  171. libraries 'javax.persistence:persistence-api:1.0.2'
  172. libraries 'net.minecraft:server:1.7.10'
  173. libraries 'pw.prok:KImagine:0.1.12@jar'
  174. libraries 'org.apache.httpcomponents:httpclient:4.4.1'
  175. libraries 'colt:colt:1.2.0'
  176. }
  177.  
  178. packageUniversal {
  179. from { configurations.exported.collect { it.isDirectory() ? it : zipTree(it) } }
  180. }
  181.  
  182. def String repeat(String string, int times) {
  183. StringBuilder builder = new StringBuilder(string.length() * times)
  184. times.times { builder.append(string) }
  185. builder as String
  186. }
  187.  
  188. def generateClasspath(boolean legacy = false) {
  189. def classpath = ''
  190. configurations.libraries.resolvedConfiguration.resolvedArtifacts.collect { it.moduleVersion.id }.each {
  191. def jar = "${it.group.replace('.', '/')}/${it.name}/${it.version}/${it.name}-${it.version}.jar"
  192. classpath += " ${legacy ? 'libraries/' : repeat('../', (group as String).split('\\.').length + 2)}${jar}"
  193. }
  194. return classpath.trim()
  195. }
  196.  
  197. def generateManifest(boolean legacy = false) {
  198. [
  199. 'KCauldron-Git-Branch' : gitInfo('branch'),
  200. 'KCauldron-Git-Hash' : gitInfo('fullHash'),
  201. 'KCauldron-Group' : project.group,
  202. 'KCauldron-Channel' : project.name,
  203. 'KCauldron-Version' : project.version,
  204. 'KCauldron-Legacy' : legacy,
  205. 'KCauldron-Official' : project.hasProperty('officialBuild'),
  206. 'Implementation-Vendor' : 'Prototik',
  207. 'Implementation-Title' : project.name,
  208. 'Implementation-Version': '1.7.10-R0.1-SNAPSHOT',
  209. 'Specification-Vendor' : 'Bukkit Team',
  210. 'Specification-Title' : 'Bukkit',
  211. 'Specification-Version' : '1.7.10-R0.1-SNAPSHOT',
  212. 'Forge-Version' : VersionParser.parseForgeVersion(file('forge/src/main/java/net/minecraftforge/common/ForgeVersion.java'), file('src/main/resources/fmlversion.properties')),
  213. 'TweakClass' : 'cpw.mods.fml.common.launcher.FMLTweaker',
  214. 'Main-Class' : 'cpw.mods.fml.relauncher.ServerLaunchWrapper',
  215. 'Class-Path' : generateClasspath(legacy)
  216. ]
  217. }
  218.  
  219. tasks.packageUniversal {
  220. classifier = 'server'
  221. setManifest {}
  222. manifest.attributes(generateManifest(true))
  223. }
  224.  
  225. task jar(type: Jar, dependsOn: packageUniversal) {
  226. destinationDir file("${buildDir}/distributions")
  227. from zipTree(tasks.packageUniversal.archivePath)
  228. manifest.attributes(generateManifest())
  229. }
  230.  
  231. tasks.createChangelog.onlyIf { false }
  232. tasks.packageInstaller.onlyIf { false }
  233.  
  234. task packageChangelog(type: CreateChangelog) {
  235. onlyIf { project.hasProperty('officialBuild') }
  236. classifier = 'changelog'
  237. extension = 'txt'
  238. oldChangelogUrl = "https://repo.prok.pw/${project.group.replace('.', '/')}/${project.name}/${buildInfo('version')}/${project.name}-${buildInfo('version')}-changelog.txt"
  239. hash = gitInfo('hash')
  240. message = gitInfo('message')
  241. version = project.version
  242. }
  243.  
  244. task bundleStub(type: Jar) {
  245. classifier = 'stub'
  246. manifest.attributes([
  247. 'Main-Class': 'cpw.mods.fml.relauncher.ServerLaunchWrapper',
  248. 'Class-Path': "bin/${project.group.replace('.', '/')}/${project.name}/${project.version}/${project.name}-${project.version}.jar"
  249. ])
  250. }
  251.  
  252. task installBundle(type: InstallBundle, dependsOn: jar) {
  253. serverJar tasks.jar.archivePath
  254. bootstrapClasspath configurations.bootstrap
  255. bootstrapMain 'pw.prok.bootstrap.Main'
  256. }
  257.  
  258. task packageBundle(type: Zip, dependsOn: installBundle) {
  259. classifier = 'bundle'
  260. from fileTree(installBundle.installLocation)
  261. from bundleStub
  262. rename bundleStub.archiveName, 'KCauldron.jar'
  263. }
  264.  
  265. task signJars(type: Sign, dependsOn: [packageChangelog, packageBundle, jar, 'generatePomFileForMavenPublication']) {
  266. sign packageChangelog
  267. sign packageBundle
  268. sign jar
  269. }
  270.  
  271. task signPom(type: Sign, dependsOn: 'generatePomFileForMavenPublication') {
  272. outputs.upToDateWhen { false }
  273. sign file("${buildDir}/publications/maven/pom-default.xml")
  274. }
  275.  
  276. task preparePublication(dependsOn: [signJars, signPom]) {}
  277.  
  278. def getPomSignature = {
  279. return project.tasks.signPom.signatureFiles.collect { it }[0]
  280. }
  281.  
  282. def getSignatureFiles = {
  283. def allFiles = project.tasks.signJars.signatureFiles.collect { it }
  284. def signedChangelog = allFiles.find { it.name.contains('-changelog') }
  285. def signedBundle = allFiles.find { it.name.contains('-bundle') }
  286. def signedJar = (allFiles - [signedChangelog, signedBundle])[0]
  287. return [
  288. [archive: signedChangelog, classifier: 'changelog', extension: 'txt.asc'],
  289. [archive: signedBundle, classifier: 'bundle', extension: 'zip.asc'],
  290. [archive: signedJar, classifier: null, extension: 'jar.asc']
  291. ]
  292. }
  293.  
  294. publishing {
  295. repositories {
  296. maven {
  297. name 'ProK'
  298. url 'https://repo.prok.pw/'
  299. credentials {
  300. username project.hasProperty('prokRepoUsername') ? prokRepoUsername : null
  301. password project.hasProperty('prokRepoPassword') ? prokRepoPassword : null
  302. }
  303. }
  304. }
  305.  
  306. publications {
  307. maven(MavenPublication) {
  308. getSignatureFiles().each { signature ->
  309. artifact(signature.archive) {
  310. classifier = signature.classifier
  311. extension = signature.extension
  312. }
  313. }
  314. artifact(getPomSignature()) {
  315. classifier = null
  316. extension = 'pom.asc'
  317. }
  318. artifact packageChangelog
  319. artifact packageBundle
  320. artifact jar
  321. }
  322. }
  323. }
  324.  
  325. tasks.generateProjectCauldron << {
  326. def file = new File('eclipse/cauldron/build.gradle')
  327. file.append('''
  328. repositories {
  329. clear()
  330. maven {
  331. name 'prok'
  332. url 'https://repo.prok.pw/'
  333. }
  334. maven {
  335. name 'forge'
  336. url 'http://files.minecraftforge.net/maven'
  337. }
  338. maven {
  339. name 'minecraft'
  340. url 'https://libraries.minecraft.net/'
  341. }
  342. mavenCentral()
  343. }
  344. dependencies {
  345. ''')
  346. configurations.libraries.resolvedConfiguration.resolvedArtifacts.collect { it.moduleVersion.id }.each { module ->
  347. if (['net.minecraft:server:', 'org.ow2.asm:asm-all'].findAll { (module as String).startsWith it }.size() > 0) {
  348. return
  349. }
  350. file.append(" compile '${module}'\n")
  351. }
  352. file.append('}')
  353. }
  354.  
  355. task resolveAllDependencies {
  356. doLast {
  357. configurations.each { it.resolve() }
  358. }
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement