forked from SilentChaos512/SilentGems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
494 lines (424 loc) · 14.6 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
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
maven { url = 'https://plugins.gradle.org/m2/' }
maven { url = 'https://dist.creeper.host/Sponge/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.4.0'
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
plugins {
id 'maven'
id 'maven-publish'
id "com.jfrog.bintray" version "1.8.5"
id "com.matthewprenger.cursegradle" version "1.4.0"
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'com.matthewprenger.cursegradle'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'idea'
repositories {
flatDir {
name "fileRepo"
dirs "repo"
}
mavenLocal()
jcenter()
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs = ['-Xlint:deprecation']
}
javadoc {
failOnError = false
}
archivesBaseName = project.archivesBaseName
def versionInfo = getModVersion()
System.out.println(versionInfo)
version = "${versionInfo['version']}"
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
minecraft {
mappings channel: project.mcp_channel.toString(), version: project.mcp_mappings.toString()
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
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 {
silentgems {
source sourceSets.main
}
}
}
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 {
silentgems {
source sourceSets.main
}
}
}
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', project.mod_id, '--all',
'--existing', file('src/main/resources').toString(),
'--existing', file('src/generated/resources').toString(),
'--output', file('src/generated/resources/')
mods {
silentgems {
source sourceSets.main
}
}
}
}
}
sourceSets.main.resources {
srcDir 'src/generated/resources'
}
import groovy.json.JsonSlurper
def secretFile
if (System.getenv().SECRET_FILE) {
secretFile = file System.getenv().SECRET_FILE
} else {
secretFile = file 'secret.json'
}
project.ext.secret = new Secrets()
if (secretFile.exists()) {
secretFile.withReader {
project.ext.secret.data = new JsonSlurper().parse it
}
}
repositories {
jcenter()
mavenLocal()
// Silent Lib
maven {
url "https://dl.bintray.com/silentchaos512/silent-lib"
}
maven {
url "https://dl.bintray.com/silentchaos512/silent-utils"
}
// Silent Gear
maven {
url "https://dl.bintray.com/silentchaos512/silent-gear"
}
maven {
// location of the maven that hosts JEI files
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
url = "https://modmaven.k-4u.nl"
}
// Curios
maven {
url = "https://maven.theillusivec4.top/"
}
maven {
name = "WorldStripper"
url = uri("https://maven.pkg.github.com/ewyboy/world-stripper")
credentials {
username = secret.github_username ?: System.getenv('github_username')
password = secret.github_token ?: System.getenv('github_token')
}
}
maven {
url 'https://jitpack.io'
}
}
dependencies {
minecraft "net.minecraftforge:forge:${project.forge_version}"
compile fg.deobf("net.silentchaos512:silent-lib-${project.sl_version}") {
exclude module: "forge"
}
compile fg.deobf("net.silentchaos512:silent-gear-${project.mc_version}:${project.sgear_version}") {
exclude module: 'forge'
exclude module: 'jei-1.16.3'
exclude module: 'silent-lib-1.16.3'
exclude module: 'curios-forge'
exclude module: 'Bookshelf-1.16.3'
exclude module: 'GameStages-1.16.3'
exclude module: 'World-Stripper'
}
// JEI
if (project.hasProperty('jei_version')) {
// compile against the JEI API but do not include it at runtime
compileOnly fg.deobf("mezz.jei:jei-${project.jei_version}:api")
// at runtime, use the full JEI jar
runtimeOnly fg.deobf("mezz.jei:jei-${project.jei_version}")
}
// runtimeOnly("net.silentchaos512:silents-mechanisms-${project.mc_version}:0.+") {
// exclude module: "cc-tweaked-${project.mc_version}"
// exclude module: "silent-gear-${project.mc_version}"
// }
// HWYLA
if (project.hasProperty('hwyla_version')) {
compileOnly "mcp.mobius.waila:Hwyla:${project.hwyla_version}"
}
// Curios
if (project.hasProperty('curios_version')) {
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${project.curios_version}")
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${project.curios_version}:api")
}
// World Stripper
if (project.hasProperty('world_stripper_version')) {
runtimeOnly fg.deobf("com.ewyboy.worldstripper:World-Stripper:${project.world_stripper_version}")
}
}
jar {
appendix = "${project.mc_version}"
manifest {
attributes(["Specification-Title" : project.mod_id,
"Specification-Vendor" : "SilentChaos512",
"Specification-Version" : "1.2",
"Implementation-Title" : project.name,
"Implementation-Version" : "${version}",
"Implementation-Vendor" : "SilentChaos512",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")],)
}
}
task deobfJar(type: Jar) {
appendix = "${project.mc_version}"
classifier = 'deobf'
from sourceSets.main.output
}
task sourcesJar(type: Jar) {
appendix = "${project.mc_version}"
classifier = 'sources'
from sourceSets.main.allJava
}
task javadocJar(type: Jar, dependsOn: javadoc) {
appendix = "${project.mc_version}"
classifier = 'javadoc'
from javadoc.getDestinationDir()
}
artifacts {
if (project.hasProperty('doDeobfJar')) {
archives deobfJar
}
if (project.hasProperty('doSourceJar')) {
archives sourcesJar
}
if (project.hasProperty('doJavadocJar')) {
archives javadocJar
}
}
class Secrets {
def data = null
def getProperty(String key) {
return data ? data[key] : ''
}
}
curseforge {
if (project.hasProperty('cf_project_id') && project.hasProperty('cf_release_type') && project.hasProperty('cf_changelog_filename') &&
((project.cf_release_type == 'alpha') || (project.cf_release_type == 'beta') || (project.cf_release_type == 'release'))) {
apiKey = secret.curseforgeAPIKey
project {
id = project.cf_project_id
changelog = file(project.cf_changelog_filename)
releaseType = project.cf_release_type
addGameVersion(project.mc_version)
addGameVersion('1.16.4')
mainArtifact(jar) {
// displayName = "$project.description $display_version"
relations {
requiredDependency 'silent-lib'
optionalDependency 'silent-gear'
}
}
// if (project.hasProperty('doAPIJar')) {
// addArtifact(apiJar) {
// displayName = "$project.description $display_version API"
// }
// }
// if (project.hasProperty('doSourceJar')) {
// addArtifact(sourceJar) {
// displayName = "$project.description $display_version Sources"
// }
// }
// if (project.hasProperty('doDeobfJar')) {
// addArtifact(deobfJar) {
// displayName = "$project.description $display_version Development"
// }
// }
// if (project.hasProperty('doJavadocJar')) {
// addArtifact(javadocJar) {
// displayName = "$project.description $display_version Javadoc"
// }
// }
}
}
}
// Bintray/Maven publishing
publishing {
publications {
publication(MavenPublication) {
groupId project.group
artifactId project.repoName
version "${versionInfo['version_short']}".toString()
from components.java
artifact sourcesJar
artifact javadocJar
}
}
}
bintray {
user = secret.BINTRAY_USER ?: System.getenv('BINTRAY_USER')
key = secret.BINTRAY_KEY ?: System.getenv('BINTRAY_KEY')
publications = ['publication']
pkg {
repo = project.repoName
name = "${project.repoName}-${project.mc_version}"
licenses = ["LGPL-3.0"]
vcsUrl = project.vcsUrl
version {
name = "${versionInfo['version_short']}".toString()
desc = "${project.name} (${project.mc_version}) ${versionInfo['version_short']}".toString()
released = new Date()
vcsTag = "v${versionInfo['version_short']}".toString()
}
}
}
// Version stuff
def getModVersion() {
try {
return getGitVersion()
} catch (Exception ex) {
System.out.println("Git version failed, falling back to old method")
return getVersion('VERSION', getModFile())
}
}
def getGitVersion() {
// Call git command
def outStream = new ByteArrayOutputStream()
def result = exec {
executable = 'git'
args = ['describe', '--long']
standardOutput = outStream
}
def fullVersion = outStream.toString().trim()
def matcher = fullVersion =~ /(\d+).(\d+).(\d+)-(.*)/
def maj = matcher[0][1]
def min = matcher[0][2]
def rev = matcher[0][3]
def bn = getBuildNumber()
return makeVersionMap(maj, min, rev, bn, matcher[0][4])
}
static def makeVersionMap(maj, min, rev, bn, githash) {
def out = [:]
out['build.major.number'] = maj.toString()
out['build.minor.number'] = min.toString()
out['build.revision.number'] = rev.toString()
out['build.githash'] = githash
out['build.number'] = bn.toString()
out['version_short'] = "${maj}.${min}.${rev}".toString()
out['version'] = "${maj}.${min}.${rev}+${bn}".toString()
return out
}
// Modified old version getter
def getVersion(String type, String mod_file) {
String maj = '0'
String min = '0'
String rev = '0'
String bn = getBuildNumber()
File file = file(mod_file)
def prefix = ~/^(?:public|protected|private) static final String $type = ".*$/
file.eachLine { String s ->
s = s.trim()
if (s ==~ prefix || prefix.matcher(s).matches()) {
String[] bits = s.split("=")
String interesting = bits[1].trim()
interesting = interesting.substring(1, interesting.length() - 2)
String[] pts = interesting.trim().split("\\.")
maj = pts[0] ?: '0'
min = pts[1] ?: '0'
rev = pts[2] ?: '0'
}
}
return makeVersionMap(maj, min, rev, bn, 'unknown')
}
// Used by old getVersion
String getModFile() {
String path = ''
FileTree tree = fileTree(dir: 'src/main/java')
tree.include '**/*.java'
tree.visit { element ->
if (element.file.isFile()) {
element.file.eachLine { String s ->
s = s.trim()
if (s.startsWith('@Mod(')) {
path = "src/main/java/$element.relativePath"
}
}
}
}
return path
}
// Build number tracking
String getBuildNumber() {
def versionFile = file('version.properties')
if (versionFile.canRead()) {
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
return versionProps['build_num'].toString()
}
return "1"
}
task incrementBuild {
doFirst {
def versionFile = file('version.properties')
if (versionFile.canRead()) {
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
def num = versionProps['build_num'].toInteger() + 1
println("incrementing BuildNumber to: " + num)
versionProps['build_num'] = num.toString()
versionProps.store(versionFile.newWriter(), null)
} else {
println("version.properties file not found! Ignoring.")
}
}
}
build.finalizedBy incrementBuild // only increment on successful builds
// Update JSON management
import groovy.json.JsonOutput
def writeUpdateJson() {
def version = getModVersion()['version_short']
def slurper = new JsonSlurper()
def file = new File('update.json')
def json = slurper.parse(file)
// TODO: Maybe add something to create an abbreviated changelog? May not be useful...
if (!json[project.mc_version].containsKey(version.toString()))
json[project.mc_version][version.toString()] = project.changelogUrl
json[project.mc_version] = json[project.mc_version].sort([compare: { a, b -> b.compareTo(a) }] as Comparator)
json['promos']["${project.mc_version}-latest"] = version
json['promos']["${project.mc_version}-recommended"] = version
println(json)
file.write(JsonOutput.prettyPrint(JsonOutput.toJson(json)))
}
task createUpdateJson {
doLast {
println('Updating update.json...')
writeUpdateJson()
}
}
build.finalizedBy createUpdateJson