-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
executable file
·564 lines (462 loc) · 18.2 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
plugins {
id "com.matthewprenger.cursegradle" version "1.4.0"
id "co.riiid.gradle" version "0.4.2"
id "com.github.ben-manes.versions" version "0.27.0"
id "com.jfrog.bintray" version "1.8.4"
id "maven"
id "maven-publish"
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'signing'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
/// Load configuration
loadBuildNumber()
loadConfig()
version = config.version
group = config.group // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = config.mod_id
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
//mappings channel: 'snapshot', version: '20190719-1.14.3'
mappings channel: config.mc_mappings_channel, version: config.mc_mappings_version
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
main {
source sourceSets.main
source sourceSets.test
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
main {
source sourceSets.main
source sourceSets.test
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
args '--mod', config.mod_id.toString(), '--all', '--output', file('src/generated/resources/')
mods {
main {
source sourceSets.main
source sourceSets.test
}
}
}
}
}
apply from: 'dependencies.gradle'
// Example configuration to allow publishing using the maven-publish task
// we define a custom artifact that is sourced from the reobfJar output task
// and then declare that to be published
// Note you'll need to add a repository here
def reobfFile = file("$buildDir/reobfJar/output.jar")
def reobfArtifact = artifacts.add('default', reobfFile) {
type 'jar'
builtBy 'reobfJar'
}
publishing {
publications {
mavenJava(MavenPublication) {
//artifact jar
artifact reobfArtifact
}
}
repositories {
maven {
url "file:///${project.projectDir}/mcmodsrepo"
}
}
}
// --------------------------------------------------------------------------
// Default repositories and publishing
repositories {
// see https://authors.curseforge.com/docs/api
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
//maven {
// name = "mc"
// url = "https://libraries.minecraft.net/"
//}
}
allprojects {
repositories {
jcenter()
}
apply plugin: 'java'
}
// See https://github.com/gradle/gradle/issues/8968
// See https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html
task sourceJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allJava
}
build.dependsOn sourceJar
/// Local Maven
// See https://docs.gradle.org/current/userguide/publishing_maven.html
publishing {
publications {
maven(MavenPublication) {
groupId = config.group
artifactId = config.mod_id
version = config.version
from components.java
artifact sourceJar
}
}
}
// bug workarounds with bad uploads, unsigned jars uploaded
// see https://github.com/matthewprenger/CurseGradle/issues/14
publishToMavenLocal {
dependsOn build
dependsOn publish
}
/// CurseGradle
// See https://github.com/matthewprenger/CurseGradle
curseforge {
group 'upload'
description 'Upload release to Curseforge'
apiKey = priv.curseforge_apikey
project {
id = config.curseforge_id
changelog = { ->
return getChangeInfo()
}
releaseType = config.curseforge_releasetype
if (deps.size() > 0) {
relations { doit -> deps.toSet().each { dep -> requiredLibrary dep } }
}
//mainArtifact(jar) {
// displayName = jar.archiveName
//}
// TODO see https://github.com/HyCraftHD/Worldgeneration-Profiler/blob/master/build.gradle#L141
//addArtifact(deobfJar) {
// //displayName = deobfJar.archiveName
// displayName = "${baseName}-${minecraft.version}-${version}-dev.${extension}"
// changelog = "Mappings: " + config.forge.mapping
//}
}
// bug workarounds with bad uploads, unsigned jars uploaded
// see https://github.com/matthewprenger/CurseGradle/issues/14
tasks.curseforge.dependsOn build
tasks.curseforge.dependsOn publish
}
/// Github
// See https://github.com/riiid/gradle-github-plugin
github {
group 'upload'
description 'Upload release and build artifacts to Github'
owner = config.github_userz
repo = config.github_repo
token = priv.github_token
name = "${config.version}"
targetCommitish = "${config.mc_version}"
tagName = "${config.version}"
body = getChangeInfo()
assets = [ getArchivePath() ]
}
/// Bintray
// See https://github.com/bintray/gradle-bintray-plugin#readme
def githubUrl = "https://github.com/${config.github_userz}/${config.github_repo}"
def repoUrl = "${githubUrl}.git"
bintray {
group 'upload'
description 'Upload release and build artifacts to Bintray'
user = config.bintray_user
key = priv.bintray_api_key
configurations = ['archives']
pkg {
repo = config.bintray_repo
name = config.bintray_package
licenses = ["${config.license}"]
websiteUrl = config.url
issueTrackerUrl="${githubUrl}/issues"
vcsUrl = repoUrl
labels = ['minecraft', 'forge', 'minecraft-mod' ]
publish = true
githubRepo = "${config.github_userz}/${config.github_repo}"
githubReleaseNotesFile = 'README.md'
version {
name = "${config.version}"
desc = getChangeInfo()
websiteUrl="${config.url}"
vcsTag = "${config.version}"
released = new Date()
}
}
}
// upload built mod and/or artifacts to all release/artifact locations
task uploadAll {
group 'upload'
description 'Upload built mod and/or artifacts to all release/artifact locations'
dependsOn 'publishToMavenLocal'
dependsOn 'bintrayUpload'
dependsOn 'githubRelease'
dependsOn 'curseforge'
}
// --------------------------------------------------------------------------
// Token replacement
// See https://stackoverflow.com/questions/30627918/how-is-a-token-replaced-in-a-file-for-a-gradle-build-product?rq=1
// See https://stackoverflow.com/a/54094378/5046881
import org.apache.tools.ant.filters.ReplaceTokens
task processSource(type: Sync) {
from (sourceSets.main.java) {
include "${config.group_path}/Reference.java"
filter(ReplaceTokens, tokens: ['MOD_ID' : config.mod_id.toString()])
filter(ReplaceTokens, tokens: ['MOD_NAME' : config.mod_name.toString()])
filter(ReplaceTokens, tokens: ['BUILD' : buildnum.BUILD_NUMBER.toString()])
filter(ReplaceTokens, tokens: ['VERSION' : config.version.toString()])
filter(ReplaceTokens, tokens: ['DEPENDENCIES' : config.dependencies.toString()])
filter(ReplaceTokens, tokens: ['UPDATEJSON' : config.updatejson.toString()])
if (project.hasProperty('keyStore')) {
filter(ReplaceTokens, tokens: ['FINGERPRINT' : project.signSHA1.toString()])
}
}
into "$buildDir/src"
from (sourceSets.main.java) {
exclude "${config.group_path}/Reference.java"
}
into "$buildDir/src"
}
compileJava {
source = processSource.outputs
}
// --------------------------------------------------------------------------
// Processing resources
// Must be after Maven publishing block
processResources {
// ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "minecraft.version", config.mc_version // project.minecraft.version
inputs.property "modid", config.mod_id
inputs.property "name", config.mod_name
inputs.property "description", config.mod_description
inputs.property "modversion", config.version
inputs.property "mcversion", config.mc_version // minecraft.version
inputs.property "url", config.url
inputs.property "updateJSON", config.updatejson
inputs.property "authorList", config.mod_authors
inputs.property "credits", config.mod_credits
inputs.property "logoFile", config.mod_logo
inputs.property "dependencies", config.mod_dependencies
// replace stuff in metadata files, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'pack.mcmeta', 'META-INF/mods.toml'
// replace mcmod.info variables with build.properties settings
expand(getMergedConfig())
}
// copy everything else, thats not the above listed files
from(sourceSets.main.resources.srcDirs) {
exclude 'pack.mcmeta', 'META-INF/mods.toml'
}
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
classifier = ""
//rename the default output, for some better sanity with scripts
archiveName = getArchiveName(baseName, version, extension)
exclude "**/*.bat"
exclude "**/*.psd"
exclude "**/*.exe"
from "LICENSE"
manifest {
attributes([
"Specification-Title": config.mod_name,
"Specification-Vendor": config.github_owner,
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": config.mod_name, // project.name,
"Implementation-Version": project.version,
"Implementation-Vendor" : config.version,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"Built-On": config.mc_version // project.minecraft.version
])
}
finalizedBy('reobfJar')
}
jar.finalizedBy('reobfJar')
artifacts {
archives jar
}
// --------------------------------------------------------------------------
// Local functions
/// Misc
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
// get this version's changelog from Forge-format update.json
def getChangeInfo() {
def filename = "${projectDir}/${config.changelog}"
def updateJsonFile = new File(filename)
if (!updateJsonFile.isFile()) {
throw new GradleException("${filename} missing")
}
def updateJson = new JsonSlurper().parse(updateJsonFile) as Map
// this should error if changelog is missing change for this version - add one!
def info = updateJson.find{ it.key == "${config.mc_version}"}?.value?.find{ it.key == "${config.version}"}?.value
if (!info) {
throw new GradleException("${filename} missing changelog for MC ${config.mc_version} ${config.mod_id} ${config.version}")
}
return info
}
def getArchiveName(baseName, version, extension) {
return new String("${baseName}-${config.mc_version}-${version}.${extension}")
}
def getArchiveName() {
return getArchiveName(config.mod_id, config.version, "jar")
}
// build our own archive path that is relative and unix-format
// since jar.archivePath is Windows format absolute path and github plugin makes ugly Github release asset file name from it
def getArchivePath() {
return new String("build/libs/"+getArchiveName())
}
// --------------------------------------------------------------------------
// Build number tracking
// load the previous build number, and increment in-memory for this build
def loadBuildNumber() {
ext.versionFile = file('version.properties')
ext.buildnum = new Properties([BUILD_NUMBER: "0"]);
if (versionFile.isFile()) {
versionFile.withReader { buildnum.load(it) }
}
def buildNumber = Integer.toString(Integer.parseInt(buildnum.BUILD_NUMBER) + 1)
buildnum.BUILD_NUMBER = buildNumber
}
// save the new build number
task('saveBuildNumber') {
outputs.file('version.properties')
// force to always run
outputs.upToDateWhen { false }
doLast {
versionFile.withWriter { buildnum.store(it, "Automated build number increase") }
}
}
// --------------------------------------------------------------------------
// Configuration
// parse the config file (in Groovy format)
def parseConfig(File config) {
config.withReader {
return (new ConfigSlurper().parse(config.toURI().toURL()))
}
}
// if the file exists, parse the config file (in Groovy format)
def parseConfigIf(File config) {
if (config.isFile()) {
return parseConfig(config)
}
return new ConfigObject()
}
// load build configuration properties and set any dependent data
def loadConfig() {
def configFile = file('build.properties')
ext.config = parseConfig(configFile)
def privateFile = file('private.properties')
ext.priv = parseConfigIf(privateFile)
version = config.version
group = config.group // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = config.mod_id
// build dep list for cursegradle usage
ext.deps = new JsonSlurper().parseText("[ ${config.mod_dependencies} ]") as Map
deps.remove( "mod_MinecraftForge")
// in case fingerprint was just copied-pasted from keytool, transform it into Forge expected form
if (project.hasProperty('keyStore')) {
project.signSHA1 = project.findProperty('signSHA1').replaceAll(':','').toLowerCase()
}
}
// Merge different configs before passing for expansion which can only take one config
def getMergedConfig() {
def mergedConfig = new ConfigObject()
mergedConfig << project.properties
mergedConfig << config
return mergedConfig
}
// --------------------------------------------------------------------------
// Signing
// See https://tutorials.darkhax.net/tutorials/jar_signing/
// See https://github.com/zlainsama/OfflineSkins/blob/master/build.gradle
import net.minecraftforge.gradle.common.task.SignJar
// Sign the jar file
task signJar(type: SignJar, dependsOn: jar) {
// Skips if the keyStore property is missing.
onlyIf {
project.hasProperty('keyStore')
}
// findProperty allows us to reference the property without it existing.
// Using project.propName would cause the script to fail validation if
// the property did not exist.
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = jar.archivePath
outputFile = jar.archivePath
}
// Use jarsigner to manually examine that jar is signed
task reviewSignJar(type: Exec) {
onlyIf {
project.hasProperty('keyStore')
}
outputs.upToDateWhen { false }
commandLine "" + System.getenv('JAVA_HOME') + "/bin/jarsigner", "-verify", "-verbose", "-keystore", project.findProperty('keyStore'), jar.archivePath
}
// --------------------------------------------------------------------------
// Misc
// delete lots of directories where bugs cause old dependencies and files to be used
task superClean(type: Delete) {
outputs.upToDateWhen { false }
delete ".classpath", ".project", ".settings", "bin", "build"
// Prevented by .gradle\4.9\fileContent\fileContent.lock
// delete ".gradle"
}
tasks.superClean.dependsOn clean
// force runClient to always run when requested - never UP-TO-DATE
//runClient.outputs.upToDateWhen { false }
// triggers for above functionality
build {
dependsOn 'signJar'
dependsOn 'saveBuildNumber'
}
// make build tasks run before publish, otherwise could upload MCP mapped jar instead of SRG mapped jar!
tasks.publish.dependsOn build
tasks.githubRelease.dependsOn build
tasks.bintrayUpload.dependsOn build
tasks.curseforge.dependsOn build
defaultTasks 'build'