Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.88 KB | None | 0 0
  1. buildscript {
  2. repositories {
  3. mavenLocal()
  4. maven { url = 'http://files.minecraftforge.net/maven' }
  5. jcenter()
  6. mavenCentral()
  7. }
  8. dependencies {
  9. classpath 'net.minecraftforge.gradle:ForgeGradle:3.+'
  10. }
  11. }
  12. import groovy.json.JsonSlurper
  13. import groovy.json.JsonBuilder
  14. import java.text.SimpleDateFormat
  15. import java.util.Date
  16. import java.util.LinkedHashMap
  17. import java.security.MessageDigest
  18. import java.net.URL
  19. import net.minecraftforge.gradle.common.task.ArchiveChecksum
  20. import net.minecraftforge.gradle.common.task.DownloadMavenArtifact
  21. import net.minecraftforge.gradle.common.task.SignJar
  22. import net.minecraftforge.gradle.patcher.task.ApplyBinPatches
  23. import org.apache.tools.ant.filters.ReplaceTokens
  24. import de.undercouch.gradle.tasks.download.Download
  25.  
  26. plugins {
  27. id 'net.minecrell.licenser' version '0.4'
  28. id 'org.ajoberstar.grgit' version '2.3.0'
  29. id 'de.undercouch.download' version '3.3.0'
  30. }
  31. apply plugin: 'eclipse'
  32.  
  33. group = 'net.minecraftforge'
  34. version = '1.0.0'
  35.  
  36. project(':mcp') {
  37. apply plugin: 'net.minecraftforge.gradle.forgedev.mcp'
  38. mcp {
  39. config = '1.13-2018.09.12.04.11.00'
  40. pipeline = 'joined'
  41. }
  42. }
  43.  
  44. project(':clean') {
  45. evaluationDependsOn(':mcp')
  46. apply plugin: 'eclipse'
  47. apply plugin: 'net.minecraftforge.gradle.forgedev.patcher'
  48. repositories {
  49. mavenCentral()
  50. }
  51. patcher {
  52. parent = project(':mcp')
  53. patchedSrc = file('src/main/java')
  54. mappings channel: 'snapshot', version: '20180921-1.13'
  55. mcVersion = '1.13'
  56. }
  57. task runclient(type: JavaExec) {
  58. doFirst {
  59. mkdir 'runclient'
  60. }
  61. classpath sourceSets.main.runtimeClasspath
  62. args = ['--accessToken', '0', '--version', '1.13']
  63. main 'net.minecraft.client.main.Main'
  64. workingDir 'runclient'
  65. }
  66. }
  67.  
  68. project(':forge') {
  69. evaluationDependsOn(':clean')
  70. apply plugin: 'java-library'
  71. apply plugin: 'maven-publish'
  72. apply plugin: 'eclipse'
  73. apply plugin: 'net.minecraftforge.gradle.forgedev.patcher'
  74. apply plugin: 'net.minecrell.licenser'
  75. apply plugin: 'de.undercouch.download'
  76.  
  77. compileJava.sourceCompatibility = compileJava.targetCompatibility = sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
  78.  
  79. sourceSets {
  80. main {
  81. java {
  82. srcDir "$rootDir/src/main/java"
  83. }
  84. resources {
  85. srcDir "$rootDir/src/main/resources"
  86. }
  87. }
  88. }
  89. repositories {
  90. mavenLocal()
  91. mavenCentral()
  92. }
  93. ext {
  94. MC_VERSION = '1.13'
  95. SPEC_VERSION = '15.24.0'
  96. MCP_ARTIFACT = project(':mcp').mcp.config
  97. MCP_VERSION = project(':mcp').mcp.config.version.split('-')[1] // The timestamp only.
  98. }
  99. patcher {
  100. parent = project(':clean')
  101. patches = file("$rootDir/patches/minecraft")
  102. patchedSrc = file('src/main/java')
  103. accessTransformer = file("$rootDir/src/main/resources/forge_at.cfg")
  104. exc = file("$rootDir/src/main/resources/forge.exc")
  105. srgPatches = true
  106. clientRun {
  107. main = 'net.minecraftforge.fml.LaunchTesting'
  108. environment = [
  109. target: 'fmldevclient'
  110. ]
  111. properties = [
  112. target: 'fmldevclient',
  113. assetDirectory: downloadAssets.output
  114. ]
  115. }
  116. serverRun {
  117. main = 'net.minecraftforge.fml.LaunchTesting'
  118. environment = [
  119. target: 'fmldevserver'
  120. ]
  121. }
  122. }
  123.  
  124. def getVersion = {
  125. def out = MC_VERSION.replace('-', '_') + '-' + SPEC_VERSION + '.' + (System.getenv('BUILD_NUMBER') ?: project.ext.properties.buildNumber ?: 0)
  126. def branch = grgit.branch.current().name
  127. if (branch != null && branch != 'master' && branch != 'HEAD' && branch != MC_VERSION && branch != MC_VERSION + '.0') {
  128. if (!(branch.endsWith('.x') && MC_VERSION.startsWith(branch.substring(0, branch.length() -2))))
  129. out += "-${branch}"
  130. }
  131. println('Version: ' + out)
  132. return out
  133. }
  134.  
  135. group = 'net.minecraftforge'
  136. version = getVersion()
  137. applyPatches {
  138. canonicalizeAccess true
  139. canonicalizeWhitespace true
  140. maxFuzz 3
  141. }
  142. configurations {
  143. installer {
  144. transitive = false //Don't pull all libraries, if we're missing something, add it to the installer list so the installer knows to download it.
  145. }
  146. api.extendsFrom(installer)
  147. }
  148. dependencies {
  149. api 'net.minecraft:client:1.13:extra'
  150. installer 'com.paulscode:soundsystem:2018+'
  151. installer 'org.ow2.asm:asm:6.2'
  152. installer 'org.ow2.asm:asm-commons:6.2'
  153. installer 'org.ow2.asm:asm-tree:6.2'
  154. installer 'cpw.mods:modlauncher:0.1.0'
  155. installer 'net.minecraftforge:accesstransformers:0.10+:shadowed'
  156. installer 'net.minecraftforge:eventbus:0.1+:service'
  157. installer 'net.minecraftforge:forgespi:0.1+'
  158. installer 'net.minecraftforge:coremods:0.1+'
  159. installer 'com.electronwill.night-config:core:3.4.0'
  160. installer 'com.electronwill.night-config:toml:3.4.0'
  161. installer 'org.jline:jline:3.5.1'
  162. installer 'org.apache.maven:maven-artifact:3.5.3'
  163. installer 'net.jodah:typetools:0.5.0'
  164. installer 'java3d:vecmath:1.5.2'
  165. installer 'org.apache.logging.log4j:log4j-api:2.11.1'
  166. installer 'org.apache.logging.log4j:log4j-core:2.11.1'
  167. }
  168.  
  169. task runclient(type: JavaExec, dependsOn: [":forge:downloadAssets", ":forge:extractNatives"]) {
  170. doFirst {
  171. mkdir 'runclient'
  172. }
  173. doFirst {
  174. copy {
  175. from sourceSets.main.resources
  176. into "$buildDir/classes/java/main"
  177. }
  178. }
  179. //jvmArgs = ['-verbose:class']
  180. classpath sourceSets.main.runtimeClasspath
  181. main 'net.minecraftforge.fml.LaunchTesting'
  182. systemProperties = [
  183. "org.lwjgl.util.Debug": "true",
  184. "org.lwjgl.util.DebugLoader": "true",
  185. "mc.version": "${MC_VERSION}",
  186. "mcp.version": "${MCP_VERSION}",
  187. "forge.version": "${project.version.substring(MC_VERSION.length() + 1)}",
  188. "forge.spec":"${SPEC_VERSION}"
  189. ]
  190. environment += [
  191. target:'fmldevclient',
  192. assetDirectory: file("${gradle.getGradleUserHomeDir()}/caches/forge_gradle/assets/"),
  193. nativesDirectory: extractNatives.output
  194. ]
  195. workingDir 'runclient'
  196. }
  197.  
  198. task runserver(type: JavaExec) {
  199. doFirst {
  200. mkdir 'runserver'
  201. }
  202. doFirst {
  203. copy {
  204. from sourceSets.main.resources
  205. into "$buildDir/classes/java/main"
  206. }
  207. }
  208. classpath sourceSets.main.runtimeClasspath
  209. main 'net.minecraftforge.fml.LaunchTesting'
  210. args 'nogui'
  211. systemProperties = [
  212. "mc.version": "${MC_VERSION}",
  213. "mcp.version": "${MCP_VERSION}",
  214. "forge.version": "${project.version.substring(MC_VERSION.length() + 1)}",
  215. "forge.spec":"${SPEC_VERSION}"
  216. ]
  217. environment target:'fmldevserver'
  218. workingDir 'runserver'
  219. standardInput = System.in
  220. }
  221.  
  222. def extraTxts = [
  223. rootProject.file('CREDITS.txt'),
  224. rootProject.file('LICENSE.txt')
  225. ]
  226. /* TODO: Changelog
  227. if (project.hasProperty('forgeJenkinsPass'))
  228. extraTxts += changelog
  229. */
  230.  
  231. task downloadCrowdin() {
  232. ext {
  233. output = file('build/crowdin_raw.zip')
  234. update = file('build/crowdin.json')
  235. id = 'minecraft-forge'
  236. }
  237. onlyIf {
  238. project.hasProperty('crowdinKey') && !project.gradle.startParameter.isOffline()
  239. }
  240. doLast {
  241. download {
  242. src "https://api.crowdin.com/api/project/${id}/export?key=${project.crowdinKey}&json"
  243. dest update
  244. overwrite true
  245. }
  246. if (!update.text.contains('success')) {
  247. throw new RuntimeException("Crowdin export failed, see ${update} for more info")
  248. }
  249. download {
  250. src "https://api.crowdin.com/api/project/${id}/download/all.zip?key=${project.crowdinKey}"
  251. dest output
  252. overwrite true
  253. }
  254. }
  255. }
  256.  
  257. task crowdin(type: Zip) {
  258. dependsOn downloadCrowdin
  259. onlyIf {
  260. !downloadCrowdin.state.skipped
  261. }
  262. baseName = project.name
  263. version = project.version
  264. classifier = 'crowdin'
  265. destinationDir = file('build/distributions')
  266. from(zipTree(downloadCrowdin.output)){
  267. eachFile { //Tired of waiting for crowdin API, rename things myself. Remove once crowdin stops being dumb
  268. if (it.name.equals('en_us.json') && !it.path.startsWith('assets/')) {
  269. it.name = it.path.split('/')[0] + '.json'
  270. it.path = 'assets/forge/lang/' + it.name
  271. }
  272. }
  273. exclude { it.isDirectory() }
  274. rename { it.toLowerCase() }//Minecraft needs it lowercase.
  275. exclude '**/*.lang' //Pre-1.13 format
  276. }
  277. }
  278.  
  279. // We apply the bin patches we just created to make a jar that is JUST our changes
  280. task applyClientBinPatches(type: ApplyBinPatches, dependsOn: genClientBinPatches) {
  281. clean = { genClientBinPatches.cleanJar }
  282. input = genClientBinPatches.output
  283. }
  284. task applyServerBinPatches(type: ApplyBinPatches, dependsOn: genServerBinPatches) {
  285. clean = { genServerBinPatches.cleanJar }
  286. input = genServerBinPatches.output
  287. }
  288. task applyJoinedBinPatches(type: ApplyBinPatches, dependsOn: genJoinedBinPatches) {
  289. clean = { genJoinedBinPatches.cleanJar }
  290. input = genJoinedBinPatches.output
  291. }
  292. // Checksum tasks so that we can know if the vanilla classes are what we expect them to do!
  293. task clientBaseChecksum(type: ArchiveChecksum, dependsOn: genClientBinPatches) {
  294. input = { genClientBinPatches.cleanJar} //Lazy because Patcher Plugin sets the value afterEvaluate
  295. name = 'client'
  296. }
  297. task serverBaseChecksum(type: ArchiveChecksum, dependsOn: genServerBinPatches) {
  298. input = { genServerBinPatches.cleanJar }
  299. name = 'server'
  300. }
  301. task joinedBaseChecksum(type: ArchiveChecksum, dependsOn: genJoinedBinPatches) {
  302. input = { genJoinedBinPatches.cleanJar }
  303. name = 'joined'
  304. }
  305. task clientPatchedChecksum(type: ArchiveChecksum, dependsOn: applyClientBinPatches) {
  306. input = applyClientBinPatches.output
  307. name = 'client_patched'
  308. }
  309. task serverPatchedChecksum(type: ArchiveChecksum, dependsOn: applyServerBinPatches) {
  310. input = applyServerBinPatches.output
  311. name = 'server_patched'
  312. }
  313. task joinedPatchedChecksum(type: ArchiveChecksum, dependsOn: applyJoinedBinPatches) {
  314. input = applyJoinedBinPatches.output
  315. name = 'joined_patched'
  316. }
  317. // Utility methods for testing checksums
  318. task cleanChecksums() {
  319. ['client', 'server', 'joined'].each { side ->
  320. ['Base', 'Patched'].each { type ->
  321. def clean = "clean${side.capitalize()}${type}Checksum"
  322. dependsOn(clean)
  323. tasks.findByName("${side}${type}Checksum").mustRunAfter(clean)
  324. }
  325. }
  326. }
  327. task checksums() {
  328. ['client', 'server', 'joined'].each { side ->
  329. ['Base', 'Patched'].each { type ->
  330. dependsOn("${side}${type}Checksum")
  331. }
  332. }
  333. }
  334.  
  335. task launcherJson(dependsOn: 'signUniversal') {
  336. inputs.file universalJar.archivePath
  337. ext {
  338. output = file('build/libs/version.json')
  339. vanilla = project(':mcp').file('build/mcp/downloadJson/version.json')
  340. timestamp = dateToIso8601(new Date())
  341. comment = [
  342. "Please do not automate the download and installation of Forge.",
  343. "Our efforts are supported by ads from the download page.",
  344. "If you MUST automate this, please consider supporting the project through https://www.patreon.com/LexManos/"
  345. ]
  346. def idx = project.version.indexOf('-')
  347. id = project.version.substring(0, idx) + "-${project.name}" + project.version.substring(idx)
  348. }
  349. inputs.file vanilla
  350. outputs.file output
  351. doLast {
  352. def json_vanilla = new JsonSlurper().parseText(vanilla.text)
  353. def json = [
  354. _comment_: comment,
  355. id: id,
  356. time: timestamp,
  357. releaseTime: timestamp,
  358. type: 'release',
  359. mainClass: 'cpw.mods.modlauncher.Launcher',
  360. inheritsFrom: MC_VERSION,
  361. logging: [ client: [
  362. argument: '-Dlog4j.configurationFile=${path}',
  363. file: [
  364. id:'client-1.12.xml',
  365. sha1:'ef4f57b922df243d0cef096efe808c72db042149',
  366. size:877,
  367. url:'https://launcher.mojang.com/v1/objects/ef4f57b922df243d0cef096efe808c72db042149/client-1.12.xml'
  368. ],
  369. type: 'log4j2-xml'
  370. ]],
  371. arguments: [
  372. game: ['--launchTarget', 'fmlclient']
  373. ],
  374. libraries: [
  375. [
  376. name: "${project.group}:${project.name}:${project.version}",
  377. downloads: [
  378. artifact: [
  379. path: "${project.group.replace('.', '/')}/${project.name}/${project.version}/${project.name}-${project.version}.jar",
  380. url: "", //Do not include the URL so that the installer/launcher won't grab it. This is also why we don't have the universal classifier
  381. sha1: sha1(universalJar.archivePath),
  382. size: universalJar.archivePath.length()
  383. ]
  384. ]
  385. ]
  386. ]
  387. ]
  388.  
  389. def artifacts = getArtifacts(project, project.configurations.installer, false)
  390. artifacts.each { key, lib ->
  391. json.libraries.add(lib)
  392. }
  393.  
  394. output.text = new JsonBuilder(json).toPrettyString()
  395. }
  396. }
  397.  
  398. task installerJson(dependsOn: [launcherJson, genClientBinPatches, applyClientBinPatches, applyServerBinPatches]) {
  399. ext {
  400. output = file('build/libs/install_profile.json')
  401. INSTALLER_TOOLS = 'net.minecraftforge:installertools:1.0.3'
  402. JAR_SPLITTER = 'net.minecraftforge:jarsplitter:1.0.4'
  403. }
  404. doFirst {
  405. ext.BIN_PATCHER = 'net.minecraftforge:binarypatcher:' + genClientBinPatches.resolvedVersion
  406. }
  407. inputs.file applyClientBinPatches.output
  408. inputs.file applyServerBinPatches.output
  409. inputs.file genClientBinPatches.toolJar
  410. inputs.file launcherJson.output
  411. outputs.file output
  412. doLast {
  413. def libs = [:]
  414. def json = [
  415. _comment_: launcherJson.comment,
  416. profile: project.name,
  417. version: launcherJson.id,
  418. json: '/version.json',
  419. path: "${project.group}:${project.name}:${project.version}",
  420. logo: '/big_logo.png',
  421. minecraft: MC_VERSION,
  422. welcome: "Welcome to the simple ${project.name.capitalize()} installer.",
  423. data: [
  424. MAPPINGS: [
  425. client: "[${MCP_ARTIFACT.group}:${MCP_ARTIFACT.name}:${MCP_ARTIFACT.version}:mappings@txt]",
  426. server: "[${MCP_ARTIFACT.group}:${MCP_ARTIFACT.name}:${MCP_ARTIFACT.version}:mappings@txt]"
  427. ],
  428. BINPATCH: [
  429. client: '/data/client.lzma',
  430. server: '/data/server.lzma'
  431. ],
  432. MC_SLIM: [
  433. client: "[net.minecraft:client:${MC_VERSION}:slim]",
  434. server: "[net.minecraft:server:${MC_VERSION}:slim]"
  435. ],
  436. MC_SLIM_SHA: [
  437. client: "'${sha1(tasks.getByName('downloadClientSlim').output)}'",
  438. server: "'${sha1(tasks.getByName('downloadServerSlim').output)}'"
  439. ],
  440. MC_DATA: [
  441. client: "[net.minecraft:client:${MC_VERSION}:data]",
  442. server: "[net.minecraft:server:${MC_VERSION}:data]"
  443. ],
  444. MC_DATA_SHA: [
  445. client: "'${sha1(tasks.getByName('downloadClientData').output)}'",
  446. server: "'${sha1(tasks.getByName('downloadServerData').output)}'"
  447. ],
  448. MC_EXTRA: [
  449. client: "[net.minecraft:client:${MC_VERSION}:extra]",
  450. server: "[net.minecraft:server:${MC_VERSION}:extra]"
  451. ],
  452. MC_EXTRA_SHA: [
  453. client: "'${sha1(tasks.getByName('downloadClientExtra').output)}'",
  454. server: "'${sha1(tasks.getByName('downloadServerExtra').output)}'"
  455. ],
  456. MC_SRG: [
  457. client: "[net.minecraft:client:${MC_VERSION}-${MCP_VERSION}:srg]",
  458. server: "[net.minecraft:server:${MC_VERSION}-${MCP_VERSION}:srg]"
  459. ],
  460. PATCHED: [
  461. client: "[${project.group}:${project.name}:${project.version}:client]",
  462. server: "[${project.group}:${project.name}:${project.version}:server]"
  463. ],
  464. PATCHED_SHA: [
  465. client: "'${sha1(applyClientBinPatches.output)}'",
  466. server: "'${sha1(applyServerBinPatches.output)}'"
  467. ]
  468. ],
  469. processors: [
  470. [
  471. jar: INSTALLER_TOOLS,
  472. classpath: getClasspath(project, libs, INSTALLER_TOOLS),
  473. args: [
  474. '--task', 'MCP_DATA',
  475. '--input', "[${MCP_ARTIFACT.descriptor}]",
  476. '--output', '{MAPPINGS}',
  477. '--key', 'mappings'
  478. ]
  479. ], [
  480. jar: JAR_SPLITTER,
  481. classpath: getClasspath(project, libs, JAR_SPLITTER),
  482. args: [
  483. '--input', '{MINECRAFT_JAR}',
  484. '--slim', '{MC_SLIM}',
  485. '--data', '{MC_DATA}',
  486. '--extra', '{MC_EXTRA}',
  487. '--srg', '{MAPPINGS}'
  488. ],
  489. outputs: [
  490. '{MC_SLIM}': '{MC_SLIM_SHA}',
  491. '{MC_DATA}': '{MC_DATA_SHA}',
  492. '{MC_EXTRA}': '{MC_EXTRA_SHA}'
  493. ]
  494. ], [ // SpecialSource has a bug where it won't create the nessasary directories, remove when they fix that.
  495. jar: INSTALLER_TOOLS,
  496. classpath: getClasspath(project, libs, INSTALLER_TOOLS),
  497. args: [
  498. '--task', 'CREATE_PARENTS',
  499. '--target', '{MC_SRG}'
  500. ]
  501. ], [
  502. jar: 'net.md-5:SpecialSource:1.8.3',
  503. classpath: getClasspath(project, libs, 'net.md-5:SpecialSource:1.8.3'),
  504. args: [
  505. '--in-jar', '{MC_SLIM}',
  506. '--out-jar', '{MC_SRG}',
  507. '--srg-in', '{MAPPINGS}'
  508. ]
  509. ], [
  510. jar: BIN_PATCHER,
  511. classpath: getClasspath(project, libs, BIN_PATCHER),
  512. args: [
  513. '--clean', '{MC_SRG}',
  514. '--output', '{PATCHED}',
  515. '--apply', '{BINPATCH}'
  516. ],
  517. outputs: [
  518. '{PATCHED}': '{PATCHED_SHA}'
  519. ]
  520. ]
  521. ]
  522. ]
  523. getClasspath(project, libs, MCP_ARTIFACT.descriptor) //Tell it to download mcp_config
  524. json.libraries = libs.values().sort{a,b -> a.name.compareTo(b.name)}
  525.  
  526. output.text = new JsonBuilder(json).toPrettyString()
  527. }
  528. }
  529.  
  530. ['client', 'server'].each { side ->
  531. ['slim', 'extra', 'data'].each { type ->
  532. def name = "download${side.capitalize()}${type.capitalize()}"
  533. task "${name}"(type: DownloadMavenArtifact) {
  534. artifact = "net.minecraft:${side}:${MC_VERSION}:${type}"
  535. }
  536. installerJson.dependsOn(name)
  537. installerJson.inputs.file(tasks.getByName(name).output)
  538. }
  539. }
  540.  
  541. universalJar {
  542. from extraTxts
  543.  
  544. /* TODO: Annotation Cache? need to talk to cpw about his new design.
  545. from(fixAnnotationsJson){
  546. into 'META-INF'
  547. }
  548. dependsOn fixAnnotationsJson
  549. */
  550.  
  551. // Add checksum files of clean and patched vanilla classes.
  552. ['client', 'server'].each { side ->
  553. ['Base', 'Patched'].each { type ->
  554. from(tasks.getByName("${side}${type}Checksum").output) {
  555. into 'checksums/'
  556. }
  557. }
  558. }
  559. dependsOn checksums
  560.  
  561. // add crowdin locales
  562. from { !crowdin.state.skipped ? zipTree(crowdin.archivePath) : null}
  563. dependsOn crowdin
  564.  
  565. doFirst {
  566. def classpath = new StringBuilder()
  567. def artifacts = getArtifacts(project, project.configurations.installer, false)
  568. artifacts.each { key, lib ->
  569. classpath += "libraries/${lib.downloads.artifact.path} "
  570. }
  571. classpath += "libraries/net/minecraft/server/${MC_VERSION}/server-${MC_VERSION}-data.jar "
  572. classpath += "libraries/net/minecraft/server/${MC_VERSION}/server-${MC_VERSION}-extra.jar"
  573.  
  574.  
  575. manifest.attributes([
  576. 'Main-Class': 'net.minecraftforge.server.ServerMain',
  577. 'Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
  578. 'GitCommit': grgit.head().getAbbreviatedId(8),
  579. 'Git-Branch': grgit.branch.current().getName(),
  580. 'Class-Path': classpath.toString()
  581. ] as LinkedHashMap)
  582. manifest.attributes([
  583. 'Specification-Title': 'Forge',
  584. 'Specification-Vendor': 'Forge Development LLC',
  585. 'Specification-Version': SPEC_VERSION,
  586. 'Implementation-Title': 'Forge',
  587. 'Implementation-Version': project.version.substring(MC_VERSION.length() + 1),
  588. 'Implementation-Vendor': 'Forge Development LLC'
  589. ] as LinkedHashMap, 'net/minecraftforge/versions/forge/')
  590. manifest.attributes([
  591. 'Specification-Title': 'Minecraft',
  592. 'Specification-Vendor': 'Mojang',
  593. 'Specification-Version': MC_VERSION,
  594. 'Implementation-Title': 'MCP',
  595. 'Implementation-Version': MCP_VERSION,
  596. 'Implementation-Vendor': 'Forge'
  597. ] as LinkedHashMap, 'net/minecraftforge/versions/mcp/')
  598. }
  599. }
  600.  
  601. task signUniversal(type: SignJar, dependsOn: universalJar) {
  602. onlyIf {
  603. project.hasProperty('jarsigner') && universalJar.state.failure == null
  604. }
  605.  
  606. def jarsigner = [:];
  607. if (project.hasProperty('jarsigner'))
  608. jarsigner = project.jarsigner;
  609.  
  610. alias = 'forge'
  611. storePass = jarsigner.storepass
  612. keyPass = jarsigner.keypass
  613. keyStore = jarsigner.keystore
  614. inputFile = universalJar.archivePath
  615. outputFile = universalJar.archivePath
  616. doFirst {
  617. project.logger.lifecycle('Signing: ' + inputFile)
  618. }
  619. }
  620. universalJar.finalizedBy(signUniversal)
  621.  
  622. task downloadInstaller(type: DownloadMavenArtifact) {
  623. artifact = 'net.minecraftforge:installer:2.0.+:shrunk'
  624. changing = true
  625. }
  626.  
  627. task installerJar(type: Zip, dependsOn: [downloadInstaller, signUniversal, installerJson, launcherJson, genClientBinPatches, genServerBinPatches]) {
  628. classifier = 'installer'
  629. extension = 'jar' //Needs to be Zip task to not override Manifest, so set extension
  630. from(extraTxts)
  631. from(rootProject.file('/src/main/resources/forge_logo.png')) {
  632. rename{'big_logo.png'}
  633. }
  634. from(rootProject.file('/src/main/resources/url.png'))
  635. from(genClientBinPatches.output) {
  636. rename{'data/client.lzma'}
  637. }
  638. from(genServerBinPatches.output) {
  639. rename{'data/server.lzma'}
  640. }
  641. from(universalJar) {
  642. into "/maven/${project.group.replace('.', '/')}/${project.name}/${project.version}/"
  643. rename { "${project.name}-${project.version}.jar" }
  644. }
  645. from(installerJson.output)
  646. from(launcherJson.output)
  647. from(zipTree(downloadInstaller.output)) {
  648. duplicatesStrategy = 'exclude'
  649. }
  650. }
  651. task signInstaller(type: SignJar, dependsOn: installerJar) {
  652. onlyIf {
  653. project.hasProperty('jarsigner') && installerJar.state.failure == null
  654. }
  655.  
  656. def jarsigner = [:];
  657. if (project.hasProperty('jarsigner'))
  658. jarsigner = project.jarsigner;
  659.  
  660. alias = 'forge'
  661. storePass = jarsigner.storepass
  662. keyPass = jarsigner.keypass
  663. keyStore = jarsigner.keystore
  664. inputFile = installerJar.archivePath
  665. outputFile = installerJar.archivePath
  666. doFirst {
  667. project.logger.lifecycle('Signing: ' + inputFile)
  668. }
  669. }
  670. installerJar.finalizedBy(signInstaller)
  671.  
  672. task makeMdk(type: Zip) {
  673. baseName = project.name
  674. classifier = 'mdk'
  675. version = project.version
  676. destinationDir = file('build/distributions')
  677.  
  678. from rootProject.file('gradlew')
  679. from rootProject.file('gradlew.bat')
  680. from extraTxts
  681. from(rootProject.file('gradle/')){
  682. into('gradle/')
  683. }
  684. from(rootProject.file('mdk/')){
  685. /* filter(ReplaceTokens, tokens: [
  686. VERSION: project.version
  687. ])
  688. */
  689. rename 'gitignore\\.txt', '.gitignore'
  690. }
  691. }
  692.  
  693. userdevConfig {
  694. def artifacts = getArtifacts(project, project.configurations.installer, true)
  695. artifacts.each { key, lib ->
  696. addLibrary(lib.name)
  697. }
  698. }
  699.  
  700. license {
  701. header = file("$rootDir/LICENSE-header.txt")
  702.  
  703. include 'net/minecraftforge/'
  704. exclude 'net/minecraftforge/server/terminalconsole/'
  705. exclude 'net/minecraftforge/api/' // exclude API here because it's validated in the SPI build
  706. exclude 'net/minecraftforge/fml/common/versioning/ComparableVersion.java'
  707. exclude 'net/minecraftforge/fml/common/versioning/InvalidVersionSpecificationException.java'
  708. exclude 'net/minecraftforge/fml/common/versioning/Restriction.java'
  709. exclude 'net/minecraftforge/fml/common/versioning/VersionRange.java'
  710.  
  711. tasks {
  712. main {
  713. files = files("$rootDir/src/main/java")
  714. }
  715. test {
  716. files = files("$rootDir/src/test/java")
  717. }
  718. }
  719. }
  720.  
  721. publishing {
  722. publications {
  723. mavenJava(MavenPublication) {
  724. artifact universalJar
  725. //TODO: changelog
  726. artifact installerJar
  727. //TODO: installer-win
  728. artifact makeMdk
  729. artifact userdevJar
  730. artifact sourcesJar
  731.  
  732. pom {
  733. name = 'forge'
  734. description = 'Modifactions to Minecraft to enable mod developers.'
  735. url = 'https://github.com/MinecraftForge/MinecraftForge'
  736.  
  737. scm {
  738. url = 'https://github.com/MinecraftForge/MinecraftForge'
  739. connection = 'scm:git:git://github.com/MinecraftForge/MinecraftForge.git'
  740. developerConnection = 'scm:git:git@github.com:MinecraftForge/MinecraftForge.git'
  741. }
  742.  
  743. issueManagement {
  744. system = 'github'
  745. url = 'https://github.com/MinecraftForge/MinecraftForge/issues'
  746. }
  747.  
  748. licenses {
  749. license {
  750. name = 'LGPL 2.1'
  751. url = 'https://github.com/MinecraftForge/MinecraftForge/blob/1.13-pre/LICENSE.txt'
  752. distribution = 'repo'
  753. }
  754. }
  755. }
  756. }
  757. }
  758. repositories {
  759. maven {
  760. if (project.hasProperty('forgeMavenPassword')) {
  761. credentials {
  762. username project.properties.forgeMavenUser
  763. password project.properties.forgeMavenPassword
  764. }
  765. url 'http://files.minecraftforge.net/maven/manage/upload'
  766. } else {
  767. url 'file://' + rootProject.file('repo').getAbsolutePath()
  768. }
  769. }
  770. }
  771. }
  772. }
  773.  
  774. def dateToIso8601(date) {
  775. def format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
  776. def result = format.format(date)
  777. return result[0..21] + ':' + result[22..-1]
  778. }
  779.  
  780. def sha1(file) {
  781. MessageDigest md = MessageDigest.getInstance('SHA-1')
  782. file.eachByte 4096, {bytes, size ->
  783. md.update(bytes, 0, size)
  784. }
  785. return md.digest().collect {String.format "%02x", it}.join()
  786. }
  787.  
  788. def artifactTree(project, artifact) {
  789. if (!project.ext.has('tree_resolver'))
  790. project.ext.tree_resolver = 1
  791. def cfg = project.configurations.create('tree_resolver_' + project.ext.tree_resolver++)
  792. def dep = project.dependencies.create(artifact)
  793. cfg.dependencies.add(dep)
  794. def files = cfg.resolve()
  795. return getArtifacts(project, cfg, true)
  796. }
  797.  
  798. def getArtifacts(project, config, classifiers) {
  799. def ret = [:]
  800. config.resolvedConfiguration.resolvedArtifacts.each {
  801. def art = [
  802. group: it.moduleVersion.id.group,
  803. name: it.moduleVersion.id.name,
  804. version: it.moduleVersion.id.version,
  805. classifier: it.classifier,
  806. extension: it.extension,
  807. file: it.file
  808. ]
  809. def key = art.group + ':' + art.name
  810. def folder = "${art.group.replace('.', '/')}/${art.name}/${art.version}/"
  811. def filename = "${art.name}-${art.version}"
  812. if (art.classifier != null)
  813. filename += "-${art.classifier}"
  814. filename += ".${art.extension}"
  815. def path = "${folder}${filename}"
  816. def url = "https://libraries.minecraft.net/${path}"
  817. if (!checkExists(url)) {
  818. url = "https://files.minecraftforge.net/maven/${path}"
  819. }
  820. //TODO remove when Mojang launcher is updated
  821. if (!classifiers && art.classifier != null) { //Mojang launcher doesn't currently support classifiers, so... move it to part of the version, and force the extension to 'jar'
  822. art.version = "${art.version}-${art.classifier}"
  823. art.classifier = null
  824. art.extension = 'jar'
  825. path = "${art.group.replace('.', '/')}/${art.name}/${art.version}/${art.name}-${art.version}.jar"
  826. }
  827. ret[key] = [
  828. name: "${art.group}:${art.name}:${art.version}" + (art.classifier == null ? '' : ":${art.classifier}") + (art.extension == 'jar' ? '' : "@${art.extension}"),
  829. downloads: [
  830. artifact: [
  831. path: path,
  832. url: url,
  833. sha1: sha1(art.file),
  834. size: art.file.length()
  835. ]
  836. ]
  837. ]
  838. }
  839. return ret
  840. }
  841.  
  842. def checkExists(url) {
  843. def code = new URL(url).openConnection().with {
  844. requestMethod = 'HEAD'
  845. connect()
  846. responseCode
  847. }
  848. return code == 200
  849. }
  850.  
  851. def getClasspath(project, libs, artifact) {
  852. def ret = []
  853. artifactTree(project, artifact).each { key, lib ->
  854. libs[lib.name] = lib
  855. if (lib.name != artifact)
  856. ret.add(lib.name)
  857. }
  858. return ret
  859. }
  860.  
  861. //evaluationDependsOnChildren()
  862. task setup() {
  863. dependsOn ':clean:extractMapped'
  864. dependsOn ':forge:extractMapped' //These must be strings so that we can do lazy resolution. Else we need evaluationDependsOnChildren above
  865. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement